From 4822de3f95e08a745e727790e1a30e49064e1e43 Mon Sep 17 00:00:00 2001 From: Markus Roberts Date: Sat, 17 Jul 2010 12:39:37 -0700 Subject: 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. --- lib/puppet/parser/lexer.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'lib/puppet/parser') diff --git a/lib/puppet/parser/lexer.rb b/lib/puppet/parser/lexer.rb index 6a9f1cfc4..1e10ff96c 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],@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 -- cgit