[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 0.25.5-663-g71824ee

Markus Roberts Markus at reality.com
Tue Jul 20 07:42:31 UTC 2010


The following commit has been merged in the upstream branch:
commit 4822de3f95e08a745e727790e1a30e49064e1e43
Author: Markus Roberts <Markus at reality.com>
Date:   Sat Jul 17 12:39:37 2010 -0700

    Fix for #4236 -- Only interpolate $ if followed by a variable
    
    This is a modification of the Nick/Jesse/Matt patch, retaining their tests and
    the analysis of the problem but reversing the implementation direction of the
    solution.
    
    Rather than trying to make the already somewhat brittle slurpstring smarter,
    which requires telling it what following strings will be accepted by the caller
    with a zero-width-lookahead negation of the regular expression used to extract
    a variable name, this patch keeps that responsibility in the caller where it
    belongs.
    
    The caller (tokenize_interpolated_string) now checks to see if it got a
    variable name _before_ emitting a variable token; if it got one, it proceeds
    normally, but if it didn't it simply tries again from that point in the string
    (accumulating the false match as a prefix).  This change actually simplifies
    the logic of tokenize_interpolated_string somewhat.

diff --git a/lib/puppet/parser/lexer.rb b/lib/puppet/parser/lexer.rb
index 6a9f1cf..1e10ff9 100644
--- a/lib/puppet/parser/lexer.rb
+++ b/lib/puppet/parser/lexer.rb
@@ -540,15 +540,17 @@ class Puppet::Parser::Lexer
     [ str[0..-2],str[-1,1] ]
   end
 
-  def tokenize_interpolated_string(token_type)
+  def tokenize_interpolated_string(token_type,preamble='')
     value,terminator = slurpstring('"$')
-    token_queue << [TOKENS[token_type[terminator]],value]
-    while terminator == '$' and not @scanner.scan(/\{/)
-      token_queue << [TOKENS[:VARIABLE], at scanner.scan(%r{(\w*::)*\w+|[0-9]})]
-      value,terminator = slurpstring('"$')
-      token_queue << [TOKENS[DQ_continuation_token_types[terminator]],value]
+    token_queue << [TOKENS[token_type[terminator]],preamble+value]
+    if terminator != '$' or @scanner.scan(/\{/)
+      token_queue.shift 
+    elsif var_name = @scanner.scan(%r{(\w*::)*\w+|[0-9]})
+      token_queue << [TOKENS[:VARIABLE],var_name]
+      tokenize_interpolated_string(DQ_continuation_token_types)
+    else
+      tokenize_interpolated_string(token_type,token_queue.pop.last + terminator)
     end
-    token_queue.shift
   end
 
   # just parse a string, not a whole file
diff --git a/spec/unit/parser/lexer_spec.rb b/spec/unit/parser/lexer_spec.rb
index 81e76a3..d3d2a0a 100755
--- a/spec/unit/parser/lexer_spec.rb
+++ b/spec/unit/parser/lexer_spec.rb
@@ -426,7 +426,13 @@ describe Puppet::Parser::Lexer,"when lexing strings" do
     %q{a hardest "scanner \"test\""}                                => [[:NAME,"a"],[:NAME,"hardest"],[:STRING,'scanner "test"']],
     %Q{a hardestest "scanner \\"test\\"\n"}                         => [[:NAME,"a"],[:NAME,"hardestest"],[:STRING,%Q{scanner "test"\n}]],
     %q{function("call")}                                            => [[:NAME,"function"],[:LPAREN,"("],[:STRING,'call'],[:RPAREN,")"]],
-    %q["string with ${(3+5)/4} nested math."]                       => [[:DQPRE,"string with "],:LPAREN,[:NAME,"3"],:PLUS,[:NAME,"5"],:RPAREN,:DIV,[:NAME,"4"],[:DQPOST," nested math."]]
+    %q["string with ${(3+5)/4} nested math."]                       => [[:DQPRE,"string with "],:LPAREN,[:NAME,"3"],:PLUS,[:NAME,"5"],:RPAREN,:DIV,[:NAME,"4"],[:DQPOST," nested math."]],
+    %q["$$$$"]                                                      => [[:STRING,"$$$$"]],
+    %q["$variable"]                                                 => [[:DQPRE,""],[:VARIABLE,"variable"],[:DQPOST,""]],
+    %q["$var$other"]                                                => [[:DQPRE,""],[:VARIABLE,"var"],[:DQMID,""],[:VARIABLE,"other"],[:DQPOST,""]],
+    %q["foo$bar$"]                                                  => [[:DQPRE,"foo"],[:VARIABLE,"bar"],[:DQPOST,"$"]],
+    %q["foo$$bar"]                                                  => [[:DQPRE,"foo$"],[:VARIABLE,"bar"],[:DQPOST,""]],
+    %q[""]                                                          => [[:STRING,""]],
   }.each { |src,expected_result|
     it "should handle #{src} correctly" do
       tokens_scanned_from(src).should be_like(*expected_result)

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list