diff options
| author | Ian Lance Taylor <iant@golang.org> | 2021-01-22 14:54:23 -0800 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2021-01-25 20:41:05 +0000 |
| commit | 3d85c69a0bf67adec57b76511ccc5e5b0ba9cdf4 (patch) | |
| tree | 523c7ee20a7f03c0985e1e442f663d0999261e81 /src/html/template/exec_test.go | |
| parent | 54514c6b2896c6a634a7b8017ade909985172e4d (diff) | |
| download | go-3d85c69a0bf67adec57b76511ccc5e5b0ba9cdf4.tar.xz | |
html/template: revert "avoid race when escaping updates template"
This reverts CLs 274450 and 279492, except for the new tests.
The new race test is changed to skip, as it now fails.
We can try again for 1.17.
Original CL descriptions:
html/template: attach functions to namespace
The text/template functions are stored in a data structure shared by
all related templates, so do the same with the original, unwrapped,
functions on the html/template side.
html/template: avoid race when escaping updates template
For #39807
Fixes #43855
Change-Id: I2ce91321ada06ea496a982aefe170eb5af9ba847
Reviewed-on: https://go-review.googlesource.com/c/go/+/285957
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Diffstat (limited to 'src/html/template/exec_test.go')
| -rw-r--r-- | src/html/template/exec_test.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/html/template/exec_test.go b/src/html/template/exec_test.go index cd6b78a1a9..7d1bef1782 100644 --- a/src/html/template/exec_test.go +++ b/src/html/template/exec_test.go @@ -1720,6 +1720,8 @@ var v = "v"; ` func TestEscapeRace(t *testing.T) { + t.Skip("this test currently fails with -race; see issue #39807") + tmpl := New("") _, err := tmpl.New("templ.html").Parse(raceText) if err != nil { @@ -1777,6 +1779,39 @@ func TestRecursiveExecute(t *testing.T) { } } +// recursiveInvoker is for TestRecursiveExecuteViaMethod. +type recursiveInvoker struct { + t *testing.T + tmpl *Template +} + +func (r *recursiveInvoker) Recur() (string, error) { + var sb strings.Builder + if err := r.tmpl.ExecuteTemplate(&sb, "subroutine", nil); err != nil { + r.t.Fatal(err) + } + return sb.String(), nil +} + +func TestRecursiveExecuteViaMethod(t *testing.T) { + tmpl := New("") + top, err := tmpl.New("x.html").Parse(`{{.Recur}}`) + if err != nil { + t.Fatal(err) + } + _, err = tmpl.New("subroutine").Parse(`<a href="/x?p={{"'a<b'"}}">`) + if err != nil { + t.Fatal(err) + } + r := &recursiveInvoker{ + t: t, + tmpl: tmpl, + } + if err := top.Execute(io.Discard, r); err != nil { + t.Fatal(err) + } +} + // Issue 43295. func TestTemplateFuncsAfterClone(t *testing.T) { s := `{{ f . }}` |
