Commit cf59c1f9 authored by Nodir Turakulov's avatar Nodir Turakulov Committed by Andrew Gerrand

html/template: include itself while cloning

template.Clone() initialized template set incorrectly:
it didn't include itself.

* include itself in template set while cloning
* add a test

Fixes #12996

Change-Id: I932530e4f7f1bbebf833e12b000a5ce052bc9223
Reviewed-on: https://go-review.googlesource.com/16104Reviewed-by: 's avatarAndrew Gerrand <adg@golang.org>
parent 09eb5889
......@@ -230,6 +230,7 @@ func (t *Template) Clone() (*Template, error) {
set: make(map[string]*Template),
},
}
ret.set[ret.Name()] = ret
for _, x := range textClone.Templates() {
name := x.Name()
src := t.set[name]
......
package template
import (
"bytes"
"testing"
)
func TestTemplateClone(t *testing.T) {
// https://golang.org/issue/12996
orig := New("name")
clone, err := orig.Clone()
if err != nil {
t.Fatal(err)
}
if len(clone.Templates()) != len(orig.Templates()) {
t.Fatalf("Invalid lenth of t.Clone().Templates()")
}
const want = "stuff"
parsed := Must(clone.Parse(want))
var buf bytes.Buffer
err = parsed.Execute(&buf, nil)
if err != nil {
t.Fatal(err)
}
if got := buf.String(); got != want {
t.Fatalf("got %q; want %q", got, want)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment