Single quoted used to allow escape on single quotes and pass all other
characters through without comment; now the do again.

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

diff --git a/lib/puppet/parser/lexer.rb b/lib/puppet/parser/lexer.rb
index 1e10ff9..aa04f17 100644
--- a/lib/puppet/parser/lexer.rb
+++ b/lib/puppet/parser/lexer.rb
@@ -221,7 +221,7 @@ class Puppet::Parser::Lexer
   TOKENS.add_token :RETURN, "\n", :skip => true, :incr_line => true, 
:skip_text => true
 
   TOKENS.add_token :SQUOTE, "'" do |lexer, value|
-    [TOKENS[:STRING], lexer.slurpstring(value).first ]
+    [TOKENS[:STRING], 
lexer.slurpstring(value,["'"],:ignore_invalid_esapes).first ]
   end
 
   DQ_initial_token_types      = {'$' => :DQPRE,'"' => :STRING}
@@ -517,8 +517,7 @@ class Puppet::Parser::Lexer
 
   # we've encountered the start of a string...
   # slurp in the rest of the string and return it
-  Valid_escapes_in_strings = %w{ \\  $ ' " n t s }+["\n"]
-  def slurpstring(terminators)
+  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}'"
@@ -529,10 +528,10 @@ class Puppet::Parser::Lexer
       when 't'; "\t"
       when 's'; " "
       else
-        if Valid_escapes_in_strings.include? ch and not (ch == '"' and 
terminators == "'")
+        if escapes.include? ch
           ch
         else
-          Puppet.warning "Unrecognised escape sequence '\\#{ch}'#{file && " in 
file #{file}"}#{line && " at line #{line}"}"
+          Puppet.warning "Unrecognised escape sequence '\\#{ch}'#{file && " in 
file #{file}"}#{line && " at line #{line}"}" unless ignore_invalid_escapes
           "\\#{ch}"
         end
       end
diff --git a/spec/unit/parser/lexer_spec.rb b/spec/unit/parser/lexer_spec.rb
index d3d2a0a..a85d1b2 100755
--- a/spec/unit/parser/lexer_spec.rb
+++ b/spec/unit/parser/lexer_spec.rb
@@ -410,6 +410,9 @@ describe Puppet::Parser::Lexer,"when lexing strings" do
     %q{'single quoted string')}                                     => 
[[:STRING,'single quoted string']],
     %q{"double quoted string"}                                      => 
[[:STRING,'double quoted string']],
     %q{'single quoted string with an escaped "\\'"'}                => 
[[:STRING,'single quoted string with an escaped "\'"']],
+    %q{'single quoted string with an escaped "\$"'}                 => 
[[:STRING,'single quoted string with an escaped "\$"']],
+    %q{'single quoted string with an escaped "\."'}                 => 
[[:STRING,'single quoted string with an escaped "\."']],
+    %q{'single quoted string with an escaped "\\\\"'}               => 
[[:STRING,'single quoted string with an escaped "\\\\"']],
     %q{"string with an escaped '\\"'"}                              => 
[[:STRING,"string with an escaped '\"'"]],
     %q{"string with an escaped '\\$'"}                              => 
[[:STRING,"string with an escaped '$'"]],
     %q{"string with $v (but no braces)"}                            => 
[[:DQPRE,"string with "],[:VARIABLE,'v'],[:DQPOST,' (but no braces)']],
-- 
1.6.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