Commit d0132282 authored by Ian Lance Taylor's avatar Ian Lance Taylor

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: 's avatarDaniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent ee0aa396
......@@ -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)
}
}
......@@ -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))
}
......
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