1
0
mirror of https://github.com/golang/go synced 2024-09-25 15:10:11 -06:00

template: fix quote-handling with formatters

Fixes issue #1896.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/4539093
This commit is contained in:
Gustavo Niemeyer 2011-05-29 00:23:32 -03:00
parent 0f4510b370
commit e11d94fcd7
2 changed files with 9 additions and 4 deletions

View File

@ -395,10 +395,11 @@ func words(buf []byte) []string {
} else {
i++
}
} else {
for i < len(buf) && !white(buf[i]) {
i++
}
}
// Even with quotes, break on whitespace only. This will
// work with e.g. {""|} and catch quoting mistakes properly.
for i < len(buf) && !white(buf[i]) {
i++
}
s = append(s, string(buf[start:i]))
}

View File

@ -762,6 +762,10 @@ var formatterTests = []Test{
in: `{"%.02f 0x%02X" 1.1 10|printf}`,
out: "1.10 0x0A",
},
{
in: `{""|}{""||}{""|printf}`, // Issue #1896.
out: "",
},
}
func TestFormatters(t *testing.T) {