diff options
| author | Russ Cox <rsc@golang.org> | 2022-09-22 20:56:38 -0400 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2022-09-23 15:03:43 +0000 |
| commit | 65deb9c3cea2a57b2cba892bc3dc4344ff0783c8 (patch) | |
| tree | 515c5d1148a9db09ad34556325c4f730eb9a9bce /src/text/template/parse | |
| parent | 2551324cd01b295915c10c6d3d06625676401610 (diff) | |
| download | go-65deb9c3cea2a57b2cba892bc3dc4344ff0783c8.tar.xz | |
text/template/parse: fix confusion about markers near right delims
Fixes #52527.
Fixes #55336.
Change-Id: I8f5c521c693e74451a558788909e7e4ad1cc797a
Reviewed-on: https://go-review.googlesource.com/c/go/+/433036
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Auto-Submit: Russ Cox <rsc@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'src/text/template/parse')
| -rw-r--r-- | src/text/template/parse/lex.go | 2 | ||||
| -rw-r--r-- | src/text/template/parse/lex_test.go | 17 |
2 files changed, 18 insertions, 1 deletions
diff --git a/src/text/template/parse/lex.go b/src/text/template/parse/lex.go index 3562e0abc9..3e60a1ecef 100644 --- a/src/text/template/parse/lex.go +++ b/src/text/template/parse/lex.go @@ -369,7 +369,7 @@ func lexComment(l *lexer) stateFn { // lexRightDelim scans the right delimiter, which is known to be present, possibly with a trim marker. func lexRightDelim(l *lexer) stateFn { - trimSpace := hasRightTrimMarker(l.input[l.pos:]) + _, trimSpace := l.atRightDelim() if trimSpace { l.pos += trimMarkerLen l.ignore() diff --git a/src/text/template/parse/lex_test.go b/src/text/template/parse/lex_test.go index 947889a80b..d47f10f9d5 100644 --- a/src/text/template/parse/lex_test.go +++ b/src/text/template/parse/lex_test.go @@ -491,6 +491,23 @@ func TestDelimsAlphaNumeric(t *testing.T) { } } +func TestDelimsAndMarkers(t *testing.T) { + test := lexTest{"delims that look like markers", "{{- .x -}} {{- - .x - -}}", []item{ + mkItem(itemLeftDelim, "{{- "), + mkItem(itemField, ".x"), + mkItem(itemRightDelim, " -}}"), + mkItem(itemLeftDelim, "{{- "), + mkItem(itemField, ".x"), + mkItem(itemRightDelim, " -}}"), + tEOF, + }} + items := collect(&test, "{{- ", " -}}") + + if !equal(items, test.items, false) { + t.Errorf("%s: got\n\t%v\nexpected\n\t%v", test.name, items, test.items) + } +} + var lexPosTests = []lexTest{ {"empty", "", []item{{itemEOF, 0, "", 1}}}, {"punctuation", "{{,@%#}}", []item{ |
