From: Gustavo Niemeyer Date: Sun, 29 May 2011 03:23:32 +0000 (-0300) Subject: template: fix quote-handling with formatters X-Git-Tag: weekly.2011-06-02~73 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=e11d94fcd7fc1d3c206b5dc42d2d0ce0deeda34d;p=gostls13.git template: fix quote-handling with formatters Fixes issue #1896. R=golang-dev, dsymonds CC=golang-dev https://golang.org/cl/4539093 --- diff --git a/src/pkg/template/template.go b/src/pkg/template/template.go index c00f72ac94..1eb0295a55 100644 --- a/src/pkg/template/template.go +++ b/src/pkg/template/template.go @@ -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])) } diff --git a/src/pkg/template/template_test.go b/src/pkg/template/template_test.go index a5e6a4ecc8..147a1ca217 100644 --- a/src/pkg/template/template_test.go +++ b/src/pkg/template/template_test.go @@ -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) {