]> Cypherpunks repositories - gostls13.git/commitdiff
text/template: fix newline counting in raw strings
authorDaniel Martí <mvdan@mvdan.cc>
Wed, 29 Aug 2018 13:06:31 +0000 (07:06 -0600)
committerDaniel Martí <mvdan@mvdan.cc>
Wed, 29 Aug 2018 20:36:09 +0000 (20:36 +0000)
lexRawQuote already uses the next method, which keeps track of newlines
on a character by character basis. Adding up newlines in emit again
results in the newlines being counted twice, which can mean bad position
information in error messages.

Fix that, and add a test.

Fixes #27319.

Change-Id: Id803be065c541412dc808d388bc6d8a86a0de41e
Reviewed-on: https://go-review.googlesource.com/131996
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/text/template/parse/lex.go
src/text/template/parse/parse_test.go

index fc259f351ed5f8acf87e3df6cf24ebf1ef31b540..c0843af6ede95b4868ac0615a7144cee7b303487 100644 (file)
@@ -155,7 +155,7 @@ func (l *lexer) emit(t itemType) {
        l.items <- item{t, l.start, l.input[l.start:l.pos], l.line}
        // Some items contain text internally. If so, count their newlines.
        switch t {
-       case itemText, itemRawString, itemLeftDelim, itemRightDelim:
+       case itemText, itemLeftDelim, itemRightDelim:
                l.line += strings.Count(l.input[l.start:l.pos], "\n")
        }
        l.start = l.pos
index c1f80c1326bc317d6993d1497dd4b9c7003b846f..d03987581c958d4acfb56604689d1f0565e364b1 100644 (file)
@@ -447,6 +447,9 @@ var errorTests = []parseTest{
        {"emptypipeline",
                `{{ ( ) }}`,
                hasError, `missing value for parenthesized pipeline`},
+       {"multilinerawstring",
+               "{{ $v := `\n` }} {{",
+               hasError, `multilinerawstring:2: unexpected unclosed action`},
 }
 
 func TestErrors(t *testing.T) {