aboutsummaryrefslogtreecommitdiff
path: root/src/html/template/exec_test.go
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2020-12-21 11:21:59 -0800
committerIan Lance Taylor <iant@golang.org>2021-01-07 17:51:29 +0000
commite60cffa4ca9ae726d96b53817d82d98402017772 (patch)
tree9afa0d0d1d68e952a7c8f74d3fb6623864f3af80 /src/html/template/exec_test.go
parent6da2d3b7d7f9c0063bc4128c2453db65c96f5299 (diff)
downloadgo-e60cffa4ca9ae726d96b53817d82d98402017772.tar.xz
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. For #39807 Fixes #43295 Change-Id: I9f64a0a601f1151c863a2833b5be2baf649b6cef Reviewed-on: https://go-review.googlesource.com/c/go/+/279492 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.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/html/template/exec_test.go b/src/html/template/exec_test.go
index eb00824260..cd6b78a1a9 100644
--- a/src/html/template/exec_test.go
+++ b/src/html/template/exec_test.go
@@ -1776,3 +1776,23 @@ func TestRecursiveExecute(t *testing.T) {
t.Fatal(err)
}
}
+
+// Issue 43295.
+func TestTemplateFuncsAfterClone(t *testing.T) {
+ s := `{{ f . }}`
+ want := "test"
+ orig := New("orig").Funcs(map[string]interface{}{
+ "f": func(in string) string {
+ return in
+ },
+ }).New("child")
+
+ overviewTmpl := Must(Must(orig.Clone()).Parse(s))
+ var out strings.Builder
+ if err := overviewTmpl.Execute(&out, want); err != nil {
+ t.Fatal(err)
+ }
+ if got := out.String(); got != want {
+ t.Fatalf("got %q; want %q", got, want)
+ }
+}