aboutsummaryrefslogtreecommitdiff
path: root/src/html
diff options
context:
space:
mode:
authorAriel Mashraki <ariel@mashraki.co.il>2020-04-22 22:17:56 +0300
committerDaniel Martí <mvdan@mvdan.cc>2020-08-28 21:45:12 +0000
commitc8ea03828b0645b1fd5725888e44873b75fcfbb6 (patch)
treee6ce023202b96a0474d88bcf7eb6befa9f950ab0 /src/html
parenta58a8d2e97d605f9f115a0e77ba09cd36bb82ba6 (diff)
downloadgo-c8ea03828b0645b1fd5725888e44873b75fcfbb6.tar.xz
text/template: add CommentNode to template parse tree
Fixes #34652 Change-Id: Icf6e3eda593fed826736f34f95a9d66f5450cc98 Reviewed-on: https://go-review.googlesource.com/c/go/+/229398 Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/html')
-rw-r--r--src/html/template/escape.go2
-rw-r--r--src/html/template/template_test.go16
2 files changed, 18 insertions, 0 deletions
diff --git a/src/html/template/escape.go b/src/html/template/escape.go
index f12dafa870..8739735cb7 100644
--- a/src/html/template/escape.go
+++ b/src/html/template/escape.go
@@ -124,6 +124,8 @@ func (e *escaper) escape(c context, n parse.Node) context {
switch n := n.(type) {
case *parse.ActionNode:
return e.escapeAction(c, n)
+ case *parse.CommentNode:
+ return c
case *parse.IfNode:
return e.escapeBranch(c, &n.BranchNode, "if")
case *parse.ListNode:
diff --git a/src/html/template/template_test.go b/src/html/template/template_test.go
index 86bd4db444..1f2c888bbe 100644
--- a/src/html/template/template_test.go
+++ b/src/html/template/template_test.go
@@ -10,6 +10,7 @@ import (
. "html/template"
"strings"
"testing"
+ "text/template/parse"
)
func TestTemplateClone(t *testing.T) {
@@ -160,6 +161,21 @@ func TestStringsInScriptsWithJsonContentTypeAreCorrectlyEscaped(t *testing.T) {
}
}
+func TestSkipEscapeComments(t *testing.T) {
+ c := newTestCase(t)
+ tr := parse.New("root")
+ tr.Mode = parse.ParseComments
+ newT, err := tr.Parse("{{/* A comment */}}{{ 1 }}{{/* Another comment */}}", "", "", make(map[string]*parse.Tree))
+ if err != nil {
+ t.Fatalf("Cannot parse template text: %v", err)
+ }
+ c.root, err = c.root.AddParseTree("root", newT)
+ if err != nil {
+ t.Fatalf("Cannot add parse tree to template: %v", err)
+ }
+ c.mustExecute(c.root, nil, "1")
+}
+
type testCase struct {
t *testing.T
root *Template