Skip to content

Commit 65deb9c

Browse files
rscgopherbot
authored andcommitted
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 <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Rob Pike <[email protected]> Auto-Submit: Russ Cox <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent 2551324 commit 65deb9c

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Diff for: src/text/template/parse/lex.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ func lexComment(l *lexer) stateFn {
369369

370370
// lexRightDelim scans the right delimiter, which is known to be present, possibly with a trim marker.
371371
func lexRightDelim(l *lexer) stateFn {
372-
trimSpace := hasRightTrimMarker(l.input[l.pos:])
372+
_, trimSpace := l.atRightDelim()
373373
if trimSpace {
374374
l.pos += trimMarkerLen
375375
l.ignore()

Diff for: src/text/template/parse/lex_test.go

+17
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,23 @@ func TestDelimsAlphaNumeric(t *testing.T) {
491491
}
492492
}
493493

494+
func TestDelimsAndMarkers(t *testing.T) {
495+
test := lexTest{"delims that look like markers", "{{- .x -}} {{- - .x - -}}", []item{
496+
mkItem(itemLeftDelim, "{{- "),
497+
mkItem(itemField, ".x"),
498+
mkItem(itemRightDelim, " -}}"),
499+
mkItem(itemLeftDelim, "{{- "),
500+
mkItem(itemField, ".x"),
501+
mkItem(itemRightDelim, " -}}"),
502+
tEOF,
503+
}}
504+
items := collect(&test, "{{- ", " -}}")
505+
506+
if !equal(items, test.items, false) {
507+
t.Errorf("%s: got\n\t%v\nexpected\n\t%v", test.name, items, test.items)
508+
}
509+
}
510+
494511
var lexPosTests = []lexTest{
495512
{"empty", "", []item{{itemEOF, 0, "", 1}}},
496513
{"punctuation", "{{,@%#}}", []item{

0 commit comments

Comments
 (0)