From c05d7a6acdcd56f00d84dfd1c48fd784dd18dbef Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 12 Jan 2015 10:59:43 -0800 Subject: [PATCH] config/lang: escaping interpolations with double dollar signs --- config/lang/lex.go | 16 +++++++++++++--- config/lang/lex_test.go | 10 ++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/config/lang/lex.go b/config/lang/lex.go index 30be9b072..7f2a85ae7 100644 --- a/config/lang/lex.go +++ b/config/lang/lex.go @@ -299,9 +299,19 @@ func (x *parserLex) lexString(yylval *parserSymType, quoted bool) (int, bool) { // If we hit a dollar sign, then check if we're starting // another interpolation. If so, then we're done. - if c == '$' && x.peek() == '{' { - x.backup() - break + if c == '$' { + n := x.peek() + + // If it is '{', then we're starting another interpolation + if n == '{' { + x.backup() + break + } + + // If it is '$', then we're escaping a dollar sign + if n == '$' { + x.next() + } } if _, err := b.WriteRune(c); err != nil { diff --git a/config/lang/lex_test.go b/config/lang/lex_test.go index 73913adf6..8c5207d78 100644 --- a/config/lang/lex_test.go +++ b/config/lang/lex_test.go @@ -25,6 +25,16 @@ func TestLex(t *testing.T) { []int{STRING, PROGRAM_BRACKET_LEFT, IDENTIFIER, PROGRAM_BRACKET_RIGHT, lexEOF}, }, + { + "foo $${bar}", + []int{STRING, lexEOF}, + }, + + { + "foo $$$${bar}", + []int{STRING, lexEOF}, + }, + { "foo ${\"bar\"}", []int{STRING, PROGRAM_BRACKET_LEFT, STRING, PROGRAM_BRACKET_RIGHT, lexEOF},