]> Cypherpunks repositories - gostls13.git/commitdiff
template: fix quote-handling with formatters
authorGustavo Niemeyer <gustavo@niemeyer.net>
Sun, 29 May 2011 03:23:32 +0000 (00:23 -0300)
committerGustavo Niemeyer <gustavo@niemeyer.net>
Sun, 29 May 2011 03:23:32 +0000 (00:23 -0300)
Fixes issue #1896.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/4539093

src/pkg/template/template.go
src/pkg/template/template_test.go

index c00f72ac949d047222755ab944a5c4c89734298f..1eb0295a55e3381135fc9519a95108511c8165fe 100644 (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]))
        }
index a5e6a4ecc8a6142f9c1d6c1750bded6ada6dc99d..147a1ca2178569e631afd76e2e38db97812d4e93 100644 (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) {