Part of the ongoing refinement / cleanup of the string interpolation semantics.
When scanning for an unescaped string terminator we now also allow an 0 or more
pairs of backslashes (that is, escaped backslashes) before the terminator.

Thanks to Jacob for the test I should have added.

Signed-off-by: Markus Roberts <[email protected]>
---
 lib/puppet/parser/lexer.rb     |    2 +-
 spec/unit/parser/lexer_spec.rb |    8 ++++++++
 2 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/lib/puppet/parser/lexer.rb b/lib/puppet/parser/lexer.rb
index a25a17e..9036d65 100644
--- a/lib/puppet/parser/lexer.rb
+++ b/lib/puppet/parser/lexer.rb
@@ -520,7 +520,7 @@ class Puppet::Parser::Lexer
   def slurpstring(terminators,escapes=%w{ \\  $ ' " n t s 
}+["\n"],ignore_invalid_escapes=false)
     # we search for the next quote that isn't preceded by a
     # backslash; the caret is there to match empty strings
-    str = @scanner.scan_until(/([^\\]|^)[#{terminators}]/) or lex_error 
"Unclosed quote after '#{last}' in '#{rest}'"
+    str = @scanner.scan_until(/([^\\]|^|[^\\])([\\]{2})*[#{terminators}]/) or 
lex_error "Unclosed quote after '#{last}' in '#{rest}'"
     @line += str.count("\n") # literal carriage returns add to the line count.
     str.gsub!(/\\(.)/) {
       ch = $1
diff --git a/spec/unit/parser/lexer_spec.rb b/spec/unit/parser/lexer_spec.rb
index b27980b..2d67bf3 100755
--- a/spec/unit/parser/lexer_spec.rb
+++ b/spec/unit/parser/lexer_spec.rb
@@ -30,6 +30,14 @@ describe Puppet::Parser::Lexer do
 
       @lexer.line.should == 10
     end
+
+    it "should not think the terminator is escaped, when preceeded by an even 
number of backslashes" do
+      @lexer.line = 10
+      @lexer.string = "here\nis\nthe\nstring\\\\'with\nextra\njunk"
+      @lexer.slurpstring("'")
+
+      @lexer.line.should == 13
+    end
   end
 end
 
-- 
1.7.0.4

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to