Commit e11d94fc authored by Gustavo Niemeyer's avatar Gustavo Niemeyer

template: fix quote-handling with formatters

Fixes issue #1896.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/4539093
parent 0f4510b3
...@@ -395,11 +395,12 @@ func words(buf []byte) []string { ...@@ -395,11 +395,12 @@ func words(buf []byte) []string {
} else { } else {
i++ i++
} }
} else { }
// 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]) { for i < len(buf) && !white(buf[i]) {
i++ i++
} }
}
s = append(s, string(buf[start:i])) s = append(s, string(buf[start:i]))
} }
return s return s
......
...@@ -762,6 +762,10 @@ var formatterTests = []Test{ ...@@ -762,6 +762,10 @@ var formatterTests = []Test{
in: `{"%.02f 0x%02X" 1.1 10|printf}`, in: `{"%.02f 0x%02X" 1.1 10|printf}`,
out: "1.10 0x0A", out: "1.10 0x0A",
}, },
{
in: `{""|}{""||}{""|printf}`, // Issue #1896.
out: "",
},
} }
func TestFormatters(t *testing.T) { func TestFormatters(t *testing.T) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment