diff options
author | Rob Pike <r@golang.org> | 2012-08-24 13:00:24 -0700 |
---|---|---|
committer | Rob Pike <r@golang.org> | 2012-08-24 13:00:24 -0700 |
commit | 51696175bddb32155128ef0a98beeecb11035f92 (patch) | |
tree | 9b1e1f729860541827e08b92e2556757e2e4d1b1 /src/pkg/text | |
parent | 59c27534e51b19d8d6c544a0af28a92d43c9f464 (diff) | |
download | go-51696175bddb32155128ef0a98beeecb11035f92.tar.gz |
text/template: catch (A).X as a parse error
This shouldn't be an error (see issue 3999), but until it's handled
correctly, treat it as one to avoid confusion. Without this CL,
(A).X parses as two arguments.
R=golang-dev, rsc
CC=golang-dev
http://codereview.appspot.com/6473059
Diffstat (limited to 'src/pkg/text')
-rw-r--r-- | src/pkg/text/template/parse/lex.go | 6 | ||||
-rw-r--r-- | src/pkg/text/template/parse/parse_test.go | 3 |
2 files changed, 9 insertions, 0 deletions
diff --git a/src/pkg/text/template/parse/lex.go b/src/pkg/text/template/parse/lex.go index c73f533d1..2f4c6ffe6 100644 --- a/src/pkg/text/template/parse/lex.go +++ b/src/pkg/text/template/parse/lex.go @@ -354,6 +354,12 @@ func lexInsideAction(l *lexer) stateFn { if l.parenDepth < 0 { return l.errorf("unexpected right paren %#U", r) } + // Catch the mistake of (a).X, which will parse as two args. + // See issue 3999. TODO: Remove once arg parsing is + // better defined. + if l.peek() == '.' { + return l.errorf("cannot evaluate field of parenthesized expression") + } return lexInsideAction case r <= unicode.MaxASCII && unicode.IsPrint(r): l.emit(itemChar) diff --git a/src/pkg/text/template/parse/parse_test.go b/src/pkg/text/template/parse/parse_test.go index da0df2095..da1ce1dd1 100644 --- a/src/pkg/text/template/parse/parse_test.go +++ b/src/pkg/text/template/parse/parse_test.go @@ -232,6 +232,9 @@ var parseTests = []parseTest{ {"invalid punctuation", "{{printf 3, 4}}", hasError, ""}, {"multidecl outside range", "{{with $v, $u := 3}}{{end}}", hasError, ""}, {"too many decls in range", "{{range $u, $v, $w := 3}}{{end}}", hasError, ""}, + // This one should work but doesn't. Caught as a parse error to avoid confusion. + // TODO: Update after issue 3999 is resolved. + {"dot applied to parentheses", "{{printf (printf .).}}", hasError, ""}, // Equals (and other chars) do not assignments make (yet). {"bug0a", "{{$x := 0}}{{$x}}", noError, "{{$x := 0}}{{$x}}"}, {"bug0b", "{{$x = 1}}{{$x}}", hasError, ""}, |