diff options
author | Ian Lance Taylor <iant@golang.org> | 2018-04-10 07:08:45 -0700 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2018-04-10 14:26:58 +0000 |
commit | d01322826e38fb42d4cf14188164fc46d90e25ae (patch) | |
tree | 9295e3a105988534b99dd6fde890a0d50304ef2a /src | |
parent | ee0aa3965726111689955e248004ce4e48f7bc63 (diff) | |
download | go-git-d01322826e38fb42d4cf14188164fc46d90e25ae.tar.gz |
text/template: copy Decl field when copying PipeNode
Fixes #24791
Change-Id: I62ac17313e6e09796586911d88191a36d67f9aa1
Reviewed-on: https://go-review.googlesource.com/106115
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Daniel Martà <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/html/template/clone_test.go | 15 | ||||
-rw-r--r-- | src/text/template/parse/node.go | 1 |
2 files changed, 16 insertions, 0 deletions
diff --git a/src/html/template/clone_test.go b/src/html/template/clone_test.go index b500715ac6..e292321d93 100644 --- a/src/html/template/clone_test.go +++ b/src/html/template/clone_test.go @@ -9,6 +9,7 @@ import ( "errors" "fmt" "io/ioutil" + "strings" "sync" "testing" "text/template/parse" @@ -262,3 +263,17 @@ func TestCloneRedefinedName(t *testing.T) { } } } + +// Issue 24791. +func TestClonePipe(t *testing.T) { + a := Must(New("a").Parse(`{{define "a"}}{{range $v := .A}}{{$v}}{{end}}{{end}}`)) + data := struct{ A []string }{A: []string{"hi"}} + b := Must(a.Clone()) + var buf strings.Builder + if err := b.Execute(&buf, &data); err != nil { + t.Fatal(err) + } + if got, want := buf.String(), "hi"; got != want { + t.Errorf("got %q want %q", got, want) + } +} diff --git a/src/text/template/parse/node.go b/src/text/template/parse/node.go index 737172dfdd..0bb96fc2e9 100644 --- a/src/text/template/parse/node.go +++ b/src/text/template/parse/node.go @@ -192,6 +192,7 @@ func (p *PipeNode) CopyPipe() *PipeNode { vars = append(vars, d.Copy().(*AssignNode)) } n := p.tr.newPipeline(p.Pos, p.Line, vars) + n.Decl = p.Decl for _, c := range p.Cmds { n.append(c.Copy().(*CommandNode)) } |