summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-09-28 11:50:56 -0700
committerMarkus Roberts <Markus@reality.com>2010-09-28 19:42:06 -0700
commit53a2bea4ddad0a9f0d537fd8833a437ed2376889 (patch)
treeea4e3973c32120fa753eb984a964e7f961c162b1
parentd12e477326a645f75cc58cc0ad7e4fd3ec7eee23 (diff)
downloadpuppet-53a2bea4ddad0a9f0d537fd8833a437ed2376889.tar.gz
puppet-53a2bea4ddad0a9f0d537fd8833a437ed2376889.tar.xz
puppet-53a2bea4ddad0a9f0d537fd8833a437ed2376889.zip
Fix for #4804 -- escaped backslashes in interpolated strings
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.
-rw-r--r--lib/puppet/parser/lexer.rb2
-rwxr-xr-xspec/unit/parser/lexer_spec.rb8
2 files changed, 9 insertions, 1 deletions
diff --git a/lib/puppet/parser/lexer.rb b/lib/puppet/parser/lexer.rb
index a25a17e3f..9036d652e 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 b27980bf2..2d67bf357 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