aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/text
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2013-07-31 15:09:13 +1000
committerRob Pike <r@golang.org>2013-07-31 15:09:13 +1000
commitdf4de948a5145519411696b4f741bcdd6480bece (patch)
tree0bc49fdd6b0445b1186e7d7a4036a1503ce1bd5d /src/pkg/text
parent221af5c12fe9769b723b8af2f000ed5f39a5dbb3 (diff)
downloadgo-df4de948a5145519411696b4f741bcdd6480bece.tar.xz
text/template/parse: print TextNodes using %s not %q
This means that printing a Node will produce output that can be used as valid input. It won't be exactly the same - some spacing may be different - but it will mean the same. Fixes #4593. R=golang-dev, dsymonds CC=golang-dev https://golang.org/cl/12006047
Diffstat (limited to 'src/pkg/text')
-rw-r--r--src/pkg/text/template/multi_test.go4
-rw-r--r--src/pkg/text/template/parse/node.go4
-rw-r--r--src/pkg/text/template/parse/parse_test.go2
3 files changed, 7 insertions, 3 deletions
diff --git a/src/pkg/text/template/multi_test.go b/src/pkg/text/template/multi_test.go
index bd98bd047e..1f6ed5d8e2 100644
--- a/src/pkg/text/template/multi_test.go
+++ b/src/pkg/text/template/multi_test.go
@@ -33,10 +33,10 @@ var multiParseTests = []multiParseTest{
nil},
{"one", `{{define "foo"}} FOO {{end}}`, noError,
[]string{"foo"},
- []string{`" FOO "`}},
+ []string{" FOO "}},
{"two", `{{define "foo"}} FOO {{end}}{{define "bar"}} BAR {{end}}`, noError,
[]string{"foo", "bar"},
- []string{`" FOO "`, `" BAR "`}},
+ []string{" FOO ", " BAR "}},
// errors
{"missing end", `{{define "foo"}} FOO `, hasError,
nil,
diff --git a/src/pkg/text/template/parse/node.go b/src/pkg/text/template/parse/node.go
index 9d0d09eb5f..dc6a3bb929 100644
--- a/src/pkg/text/template/parse/node.go
+++ b/src/pkg/text/template/parse/node.go
@@ -13,6 +13,8 @@ import (
"strings"
)
+var textFormat = "%s" // Changed to "%q" in tests for better error messages.
+
// A Node is an element in the parse tree. The interface is trivial.
// The interface contains an unexported method so that only
// types local to this package can satisfy it.
@@ -125,7 +127,7 @@ func newText(pos Pos, text string) *TextNode {
}
func (t *TextNode) String() string {
- return fmt.Sprintf("%q", t.Text)
+ return fmt.Sprintf(textFormat, t.Text)
}
func (t *TextNode) Copy() Node {
diff --git a/src/pkg/text/template/parse/parse_test.go b/src/pkg/text/template/parse/parse_test.go
index 695c76ebfe..0e5c1448c8 100644
--- a/src/pkg/text/template/parse/parse_test.go
+++ b/src/pkg/text/template/parse/parse_test.go
@@ -256,6 +256,8 @@ var builtins = map[string]interface{}{
}
func testParse(doCopy bool, t *testing.T) {
+ textFormat = "%q"
+ defer func() { textFormat = "%s" }()
for _, test := range parseTests {
tmpl, err := New(test.name).Parse(test.input, "", "", make(map[string]*Tree), builtins)
switch {