From 9163442b305190688516360068fd8b9ccaec11d6 Mon Sep 17 00:00:00 2001 From: Ariel Mashraki Date: Tue, 21 Nov 2017 17:15:53 +0200 Subject: [PATCH] parse: fix issue #8 --- parse/lex.go | 2 +- parse/parse.go | 12 +++++++++--- parse/parse_test.go | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/parse/lex.go b/parse/lex.go index 5109f81..49236b7 100644 --- a/parse/lex.go +++ b/parse/lex.go @@ -217,7 +217,7 @@ func lexSubstitution(l *lexer) stateFn { case '+': l.emit(itemColonPlus) default: - return l.errorf("expected '-', '=' or '+' after ':'") + l.emit(itemText) } default: l.emit(itemText) diff --git a/parse/parse.go b/parse/parse.go index c66eb89..28cd129 100644 --- a/parse/parse.go +++ b/parse/parse.go @@ -103,9 +103,15 @@ Loop: defaultNode = NewVariable(strings.TrimPrefix(t.val, "$"), p.Env) case itemText: n := NewText(t.val) - // patch to accept all kind of chars - for p.peek().typ != itemRightDelim { - n.Text += p.next().val + Text: + for { + switch p.peek().typ { + case itemRightDelim, itemError, itemEOF: + break Text + default: + // patch to accept all kind of chars + n.Text += p.next().val + } } defaultNode = n default: diff --git a/parse/parse_test.go b/parse/parse_test.go index 23a3e48..ad83313 100644 --- a/parse/parse_test.go +++ b/parse/parse_test.go @@ -61,6 +61,7 @@ var parseTests = []parseTest{ {"multi line string", "hello $BAR\nhello ${EMPTY:=$FOO}", "hello bar\nhello foo", errNone}, {"issue #1", "${hello:=wo_rld} ${foo:=bar_baz}", "wo_rld bar_baz", errNone}, {"issue #2", "name: ${NAME:=foo_qux}, key: ${EMPTY:=baz_bar}", "name: foo_qux, key: baz_bar", errNone}, + {"gh-issue-8", "prop=${HOME_URL-http://localhost:8080}", "prop=http://localhost:8080", errNone}, // bad substitution {"closing brace expected", "hello ${", "", errAll}, @@ -95,7 +96,6 @@ var parseTests = []parseTest{ {"$var and $DEFAULT empty :=", "${EMPTY:=$ALSO_EMPTY}", "", errEmpty}, {"$var and $OTHER empty +", "${EMPTY+$ALSO_EMPTY}", "", errEmpty}, {"$var and $OTHER empty :+", "${EMPTY:+$ALSO_EMPTY}", "", errEmpty}, - // } func TestParse(t *testing.T) {