mirror of
https://github.com/golang/go
synced 2024-11-25 06:47:56 -07:00
exp/template/html: fix bug, '<' normalization for text nodes that change context
R=nigeltao CC=golang-dev https://golang.org/cl/5080042
This commit is contained in:
parent
1f27519988
commit
1262f6bde7
@ -551,8 +551,17 @@ func (e *escaper) escapeText(c context, n *parse.TextNode) context {
|
||||
for i != len(s) {
|
||||
c1, nread := contextAfterText(c, s[i:])
|
||||
i1 := i + nread
|
||||
if c.state == c1.state && (c.state == stateText || c.state == stateRCDATA) {
|
||||
for j := i; j < i1; j++ {
|
||||
if c.state == stateText || c.state == stateRCDATA {
|
||||
end := i1
|
||||
if c1.state != c.state {
|
||||
for j := end - 1; j >= i; j-- {
|
||||
if s[j] == '<' {
|
||||
end = j
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
for j := i; j < end; j++ {
|
||||
if s[j] == '<' {
|
||||
b.Write(s[written:j])
|
||||
b.WriteString("<")
|
||||
|
@ -366,6 +366,26 @@ func TestEscape(t *testing.T) {
|
||||
// TODO: Elide comment.
|
||||
"<b>Hello, <!-- name of world --><Cincinatti></b>",
|
||||
},
|
||||
{
|
||||
"HTML comment not first < in text node.",
|
||||
"<<!-- -->!--",
|
||||
"<<!-- -->!--",
|
||||
},
|
||||
{
|
||||
"HTML normalization 1",
|
||||
"a < b",
|
||||
"a < b",
|
||||
},
|
||||
{
|
||||
"HTML normalization 2",
|
||||
"a << b",
|
||||
"a << b",
|
||||
},
|
||||
{
|
||||
"HTML normalization 3",
|
||||
"a<<!-- --><!-- -->b",
|
||||
"a<<!-- --><!-- -->b",
|
||||
},
|
||||
{
|
||||
"Split HTML comment",
|
||||
"<b>Hello, <!-- name of {{if .T}}city -->{{.C}}{{else}}world -->{{.W}}{{end}}</b>",
|
||||
|
Loading…
Reference in New Issue
Block a user