]> Cypherpunks repositories - gostls13.git/commitdiff
text/template: copy Decl field when copying PipeNode
authorIan Lance Taylor <iant@golang.org>
Tue, 10 Apr 2018 14:08:45 +0000 (07:08 -0700)
committerIan Lance Taylor <iant@golang.org>
Tue, 10 Apr 2018 14:26:58 +0000 (14:26 +0000)
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>

src/html/template/clone_test.go
src/text/template/parse/node.go

index b500715ac6efa7db239d74cd1689b6c43bce519a..e292321d9367c42d4bddc6094523e5d7d43a2d82 100644 (file)
@@ -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)
+       }
+}
index 737172dfddbd8021dc1954ea37a01bd5e5285637..0bb96fc2e90234bc54dcb5b8f12e6b8add2ce61e 100644 (file)
@@ -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))
        }