]> Cypherpunks repositories - gostls13.git/commitdiff
html/template: add test case for unbounded template expansion
authorRuss Cox <rsc@golang.org>
Wed, 19 Oct 2016 17:34:15 +0000 (13:34 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 24 Oct 2016 15:44:30 +0000 (15:44 +0000)
Fixed by CL 31092 already, but that change is a few steps away
from the problem observed here, so add an explicit test.

Fixes #17019.

Change-Id: If4ece1418e6596b1976961347889ce12c5969637
Reviewed-on: https://go-review.googlesource.com/31466
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Quentin Smith <quentin@golang.org>
src/html/template/clone_test.go

index 069064c98b62d9acf7670150d041be809c9bf4d6..bbe44f98dd16ca51fc225b734349f065c8a04ae8 100644 (file)
@@ -229,3 +229,15 @@ func TestTemplateCloneLookup(t *testing.T) {
                t.Error("after Clone, tmpl.Lookup(tmpl.Name()) != tmpl")
        }
 }
+
+func TestCloneGrowth(t *testing.T) {
+       tmpl := Must(New("root").Parse(`<title>{{block "B". }}Arg{{end}}</title>`))
+       tmpl = Must(tmpl.Clone())
+       Must(tmpl.Parse(`{{define "B"}}Text{{end}}`))
+       for i := 0; i < 10; i++ {
+               tmpl.Execute(ioutil.Discard, nil)
+       }
+       if len(tmpl.DefinedTemplates()) > 200 {
+               t.Fatalf("too many templates: %v", len(tmpl.DefinedTemplates()))
+       }
+}