summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryan Kearney <bkearney@redhat.com>2010-03-22 08:36:07 -0400
committerJames Turnbull <james@lovedthanlost.net>2010-03-24 09:32:01 +1100
commit7ec50a74f81264591208fb55e01567ee795ab6b8 (patch)
treee1e374a3553d4738c223489ba9155db646b2a21a
parentd561a988c53d521d0fecf06c4f4d8a65267ac005 (diff)
Fixes #3387 - Handle path elements with ticks and spaces
Unit tests for path changes
-rw-r--r--lib/puppet/provider/augeas/augeas.rb12
-rw-r--r--lib/puppet/type/augeas.rb2
-rw-r--r--spec/unit/provider/augeas/augeas.rb14
3 files changed, 24 insertions, 4 deletions
diff --git a/lib/puppet/provider/augeas/augeas.rb b/lib/puppet/provider/augeas/augeas.rb
index 5b9133a92..6e471b8e8 100644
--- a/lib/puppet/provider/augeas/augeas.rb
+++ b/lib/puppet/provider/augeas/augeas.rb
@@ -82,18 +82,24 @@ Puppet::Type.type(:augeas).provide(:augeas) do
if f == :path
start = sc.pos
nbracket = 0
+ inSingleTick = false
+ inDoubleTick = false
begin
- sc.skip(/([^\]\[\s\\]|\\.)+/)
+ sc.skip(/([^\]\[\s\\'"]|\\.)+/)
ch = sc.getch
nbracket += 1 if ch == "["
nbracket -= 1 if ch == "]"
+ inSingleTick = !inSingleTick if ch == "'"
+ inDoubleTick = !inDoubleTick if ch == "\""
fail("unmatched [") if nbracket < 0
- end until nbracket == 0 && (sc.eos? || ch =~ /\s/)
+ end until ((nbracket == 0 && !inSingleTick && !inDoubleTick && (ch =~ /\s/)) || sc.eos?)
len = sc.pos - start
len -= 1 unless sc.eos?
unless p = sc.string[start, len]
fail("missing path argument #{narg} for #{cmd}")
end
+ # Rip off any ticks if they are there.
+ p = p[1, (p.size - 2)] if p[0,1] == "'" || p[0,1] == "\""
p.chomp!("/")
if p[0,1] != "$" && p[0,1] != "/"
argline << context + p
@@ -278,7 +284,7 @@ Puppet::Type.type(:augeas).provide(:augeas) do
save_result = @aug.save
saved_files = @aug.match("/augeas/events/saved")
if save_result and not files_changed?
- debug("Skipping becuase no files were changed")
+ debug("Skipping because no files were changed")
return_value = false
else
debug("Files changed, should execute")
diff --git a/lib/puppet/type/augeas.rb b/lib/puppet/type/augeas.rb
index cfd1da55b..49d6d5f07 100644
--- a/lib/puppet/type/augeas.rb
+++ b/lib/puppet/type/augeas.rb
@@ -145,7 +145,7 @@ Puppet::Type.newtype(:augeas) do
end
# if the onlyif resource is provided, then the value is parsed.
- # a return value of 0 will stop exection becuase it matches the
+ # a return value of 0 will stop exection because it matches the
# default value.
def retrieve
if @resource.provider.need_to_run?()
diff --git a/spec/unit/provider/augeas/augeas.rb b/spec/unit/provider/augeas/augeas.rb
index 067126cbd..22f7bed8c 100644
--- a/spec/unit/provider/augeas/augeas.rb
+++ b/spec/unit/provider/augeas/augeas.rb
@@ -141,6 +141,20 @@ describe provider_class do
tokens.should == [ args ]
end
+ it "should allow single quoted escaped spaces in paths" do
+ @resource.stubs(:[]).returns("/foo/")
+ args = [ "set", "'/white\\ space/key'", "value" ]
+ tokens = @provider.parse_commands(args.join(" \t "))
+ tokens.should == [[ "set", "/white\\ space/key", "value" ]]
+ end
+
+ it "should allow double quoted escaped spaces in paths" do
+ @resource.stubs(:[]).returns("/foo/")
+ args = [ "set", '"/white\\ space/key"', "value" ]
+ tokens = @provider.parse_commands(args.join(" \t "))
+ tokens.should == [[ "set", "/white\\ space/key", "value" ]]
+ end
+
it "should remove trailing slashes" do
@resource.stubs(:[]).returns("/foo/")
tokens = @provider.parse_commands("set foo/ bar")