diff options
author | Markus Roberts <Markus@reality.com> | 2010-07-17 12:39:37 -0700 |
---|---|---|
committer | Markus Roberts <Markus@reality.com> | 2010-07-18 19:44:19 -0700 |
commit | 4822de3f95e08a745e727790e1a30e49064e1e43 (patch) | |
tree | bd3b26ce5a8a9304509c07f5dd6da296bd9ed707 /spec | |
parent | b509032e559cb26e05863b2c290a543c6fa9d779 (diff) | |
download | puppet-4822de3f95e08a745e727790e1a30e49064e1e43.tar.gz puppet-4822de3f95e08a745e727790e1a30e49064e1e43.tar.xz puppet-4822de3f95e08a745e727790e1a30e49064e1e43.zip |
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.
Diffstat (limited to 'spec')
-rwxr-xr-x | spec/unit/parser/lexer_spec.rb | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/spec/unit/parser/lexer_spec.rb b/spec/unit/parser/lexer_spec.rb index 81e76a388..d3d2a0a31 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) |