0
1
mirror of https://github.com/golang/go synced 2025-06-07 16:40:46 +00:00

text/template/parse: use correct line number in error after comment

Fixes 

Change-Id: I42467ddec02e91f24bce87185bf8d7f16f8811b0
GitHub-Last-Rev: 039a5b6884
GitHub-Pull-Request: 
Reviewed-on: https://go-review.googlesource.com/c/go/+/614375
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
This commit is contained in:
yincong
2024-09-22 08:05:02 +00:00
committed by Gopher Robot
parent 530fbb283c
commit 7d114b5b71
2 changed files with 11 additions and 0 deletions
src/text/template/parse

@ -352,6 +352,7 @@ func lexComment(l *lexer) stateFn {
if !delim {
return l.errorf("comment ends before closing delimiter")
}
l.line += strings.Count(l.input[l.start:l.pos], "\n")
i := l.thisItem(itemComment)
if trimSpace {
l.pos += trimMarkerLen

@ -545,6 +545,16 @@ var lexPosTests = []lexTest{
{itemRightDelim, 11, "}}", 2},
{itemEOF, 13, "", 2},
}},
{"longcomment", "{{/*\n*/}}\n{{undefinedFunction \"test\"}}", []item{
{itemComment, 2, "/*\n*/", 1},
{itemText, 9, "\n", 2},
{itemLeftDelim, 10, "{{", 3},
{itemIdentifier, 12, "undefinedFunction", 3},
{itemSpace, 29, " ", 3},
{itemString, 30, "\"test\"", 3},
{itemRightDelim, 36, "}}", 3},
{itemEOF, 38, "", 3},
}},
}
// The other tests don't check position, to make the test cases easier to construct.