diff options
| author | yincong <yincong@baidu.com> | 2024-09-22 08:05:02 +0000 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2024-09-23 18:02:15 +0000 |
| commit | 7d114b5b71a03aa90fc560878acf19cc7251d216 (patch) | |
| tree | 492a15412300edc64fb436b31ab426092babcf38 /src/text/template/parse | |
| parent | 530fbb283c911d97238cc5cacecc6b409ee7df88 (diff) | |
| download | go-7d114b5b71a03aa90fc560878acf19cc7251d216.tar.xz | |
text/template/parse: use correct line number in error after comment
Fixes #69526
Change-Id: I42467ddec02e91f24bce87185bf8d7f16f8811b0
GitHub-Last-Rev: 039a5b6884aa65f34cecbfcd127861a703a048da
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>
Diffstat (limited to 'src/text/template/parse')
| -rw-r--r-- | src/text/template/parse/lex.go | 1 | ||||
| -rw-r--r-- | src/text/template/parse/lex_test.go | 10 |
2 files changed, 11 insertions, 0 deletions
diff --git a/src/text/template/parse/lex.go b/src/text/template/parse/lex.go index 70fc86b63c..a00f48e658 100644 --- a/src/text/template/parse/lex.go +++ b/src/text/template/parse/lex.go @@ -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 diff --git a/src/text/template/parse/lex_test.go b/src/text/template/parse/lex_test.go index d47f10f9d5..20f9698fa4 100644 --- a/src/text/template/parse/lex_test.go +++ b/src/text/template/parse/lex_test.go @@ -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. |
