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 #69526
Change-Id: I42467ddec02e91f24bce87185bf8d7f16f8811b0
GitHub-Last-Rev: 039a5b6884
GitHub-Pull-Request: golang/go#69532
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:
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.
|
||||
|
Reference in New Issue
Block a user