mirror of https://github.com/golang/go.git
text/template: fix newline counting in raw strings
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>
This commit is contained in:
parent
8f4fd3f34e
commit
6fa08c0fdb
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue