mirror of
https://github.com/golang/go
synced 2024-11-17 06:04:47 -07:00
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>
This commit is contained in:
parent
2551324cd0
commit
65deb9c3ce
@ -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()
|
||||
|
@ -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{
|
||||
|
Loading…
Reference in New Issue
Block a user