Properly quote regular expression inputs to StringBlockEditor
This commit is contained in:
parent
64d1b54d51
commit
43f3764e5b
|
@ -1,6 +1,9 @@
|
||||||
## 1.1.1 (unreleased)
|
## 1.1.1 (unreleased)
|
||||||
|
|
||||||
|
BUG FIXES:
|
||||||
|
|
||||||
|
- Quote keys to StringBlockEditor so keys with spaces, parens, and
|
||||||
|
so on work properly.
|
||||||
|
|
||||||
## 1.1.0 (March 14, 2013)
|
## 1.1.0 (March 14, 2013)
|
||||||
|
|
||||||
|
|
|
@ -44,12 +44,14 @@ module Vagrant
|
||||||
|
|
||||||
# This deletes the block with the given key if it exists.
|
# This deletes the block with the given key if it exists.
|
||||||
def delete(key)
|
def delete(key)
|
||||||
|
key = Regexp.quote(key)
|
||||||
regexp = /^#\s*VAGRANT-BEGIN:\s*#{key}$.*^#\s*VAGRANT-END:\s*#{key}$\r?\n?/m
|
regexp = /^#\s*VAGRANT-BEGIN:\s*#{key}$.*^#\s*VAGRANT-END:\s*#{key}$\r?\n?/m
|
||||||
@value.gsub!(regexp, "")
|
@value.gsub!(regexp, "")
|
||||||
end
|
end
|
||||||
|
|
||||||
# This gets the value of the block with the given key.
|
# This gets the value of the block with the given key.
|
||||||
def get(key)
|
def get(key)
|
||||||
|
key = Regexp.quote(key)
|
||||||
regexp = /^#\s*VAGRANT-BEGIN:\s*#{key}$\r?\n?(.*?)\r?\n?^#\s*VAGRANT-END:\s*#{key}$\r?\n?/m
|
regexp = /^#\s*VAGRANT-BEGIN:\s*#{key}$\r?\n?(.*?)\r?\n?^#\s*VAGRANT-END:\s*#{key}$\r?\n?/m
|
||||||
match = regexp.match(@value)
|
match = regexp.match(@value)
|
||||||
return nil if !match
|
return nil if !match
|
||||||
|
|
|
@ -61,17 +61,25 @@ DATA
|
||||||
# VAGRANT-BEGIN: bar
|
# VAGRANT-BEGIN: bar
|
||||||
content
|
content
|
||||||
# VAGRANT-END: bar
|
# VAGRANT-END: bar
|
||||||
|
# VAGRANT-BEGIN: /Users/studio/Projects (studio)/tubes/.vagrant/machines/web/vmware_fusion/vm.vmwarevm
|
||||||
|
complex
|
||||||
|
# VAGRANT-END: /Users/studio/Projects (studio)/tubes/.vagrant/machines/web/vmware_fusion/vm.vmwarevm
|
||||||
DATA
|
DATA
|
||||||
end
|
end
|
||||||
|
|
||||||
|
subject { described_class.new(data) }
|
||||||
|
|
||||||
it "should get the value" do
|
it "should get the value" do
|
||||||
instance = described_class.new(data)
|
subject.get("bar").should == "content"
|
||||||
instance.get("bar").should == "content"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should get nil for nonexistent values" do
|
it "should get nil for nonexistent values" do
|
||||||
instance = described_class.new(data)
|
subject.get("baz").should be_nil
|
||||||
instance.get("baz").should be_nil
|
end
|
||||||
|
|
||||||
|
it "should get complicated keys" do
|
||||||
|
result = subject.get("/Users/studio/Projects (studio)/tubes/.vagrant/machines/web/vmware_fusion/vm.vmwarevm")
|
||||||
|
result.should == "complex"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue