diff options
| author | Rob Pike <r@golang.org> | 2013-08-27 13:29:07 +1000 |
|---|---|---|
| committer | Rob Pike <r@golang.org> | 2013-08-27 13:29:07 +1000 |
| commit | 1f661fc205440ccfb46b76a964f50a1259c928d8 (patch) | |
| tree | 996879c06f890f9e0eadd3d912db0d897c9956af /src/pkg/text/template/exec_test.go | |
| parent | 519a9e8e9bdfa9b8a1b5c0c1c5be7a16718f7992 (diff) | |
| download | go-1f661fc205440ccfb46b76a964f50a1259c928d8.tar.xz | |
text/template: make the escapers for HTML etc. handle pointers correctly
Apply the same rules for argument evaluation and indirection that are
used by the regular evaluator.
Fixes #5802
R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/13257043
Diffstat (limited to 'src/pkg/text/template/exec_test.go')
| -rw-r--r-- | src/pkg/text/template/exec_test.go | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/pkg/text/template/exec_test.go b/src/pkg/text/template/exec_test.go index 341c502173..be1a2d23d8 100644 --- a/src/pkg/text/template/exec_test.go +++ b/src/pkg/text/template/exec_test.go @@ -57,6 +57,7 @@ type T struct { Err error // Pointers PI *int + PS *string PSI *[]int NIL *int // Function (not method) @@ -125,6 +126,7 @@ var tVal = &T{ Str: bytes.NewBuffer([]byte("foozle")), Err: errors.New("erroozle"), PI: newInt(23), + PS: newString("a string"), PSI: newIntSlice(21, 22, 23), BinaryFunc: func(a, b string) string { return fmt.Sprintf("[%s=%s]", a, b) }, VariadicFunc: func(s ...string) string { return fmt.Sprint("<", strings.Join(s, "+"), ">") }, @@ -143,9 +145,11 @@ var iVal I = tVal // Helpers for creation. func newInt(n int) *int { - p := new(int) - *p = n - return p + return &n +} + +func newString(s string) *string { + return &s } func newIntSlice(n ...int) *[]int { @@ -282,6 +286,7 @@ var execTests = []execTest{ // Pointers. {"*int", "{{.PI}}", "23", tVal, true}, + {"*string", "{{.PS}}", "a string", tVal, true}, {"*[]int", "{{.PSI}}", "[21 22 23]", tVal, true}, {"*[]int[1]", "{{index .PSI 1}}", "22", tVal, true}, {"NIL", "{{.NIL}}", "<nil>", tVal, true}, @@ -391,6 +396,7 @@ var execTests = []execTest{ "<script>alert("XSS");</script>", nil, true}, {"html pipeline", `{{printf "<script>alert(\"XSS\");</script>" | html}}`, "<script>alert("XSS");</script>", nil, true}, + {"html", `{{html .PS}}`, "a string", tVal, true}, // JavaScript. {"js", `{{js .}}`, `It\'d be nice.`, `It'd be nice.`, true}, |
