]> Cypherpunks repositories - gostls13.git/commitdiff
text/template/parse: use correct line number in error after comment
authoryincong <yincong@baidu.com>
Sun, 22 Sep 2024 08:05:02 +0000 (08:05 +0000)
committerGopher Robot <gobot@golang.org>
Mon, 23 Sep 2024 18:02:15 +0000 (18:02 +0000)
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>
src/text/template/parse/lex.go
src/text/template/parse/lex_test.go

index 70fc86b63cccdc2deea9b1bc5dc7d8f523706f4f..a00f48e658ab64827ce51441787ac5af0f6921c2 100644 (file)
@@ -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
index d47f10f9d5e9b9b84b6c605ac8a28d0d1ab02d01..20f9698fa4790fe61fb14d946a9773c022fba122 100644 (file)
@@ -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.