mirror of
https://github.com/golang/go
synced 2024-11-21 21:14:47 -07:00
html: parse the contents of <iframe> elements as raw text
Pass tests5.dat, test 4: <iframe> <!---> </iframe>x | <html> | <head> | <body> | <iframe> | " <!---> " | "x" Also pass tests through test 9: <style> <!</-- </style>x R=nigeltao CC=golang-dev https://golang.org/cl/5450044
This commit is contained in:
parent
72a2979ef0
commit
e32f4ba77d
@ -153,6 +153,8 @@ func TestParser(t *testing.T) {
|
|||||||
{"tests1.dat", -1},
|
{"tests1.dat", -1},
|
||||||
{"tests2.dat", -1},
|
{"tests2.dat", -1},
|
||||||
{"tests3.dat", -1},
|
{"tests3.dat", -1},
|
||||||
|
// tests4.dat is fragment cases.
|
||||||
|
{"tests5.dat", 10},
|
||||||
}
|
}
|
||||||
for _, tf := range testFiles {
|
for _, tf := range testFiles {
|
||||||
f, err := os.Open("testdata/webkit/" + tf.filename)
|
f, err := os.Open("testdata/webkit/" + tf.filename)
|
||||||
|
@ -185,7 +185,7 @@ func render1(w writer, n *Node) error {
|
|||||||
|
|
||||||
// Render any child nodes.
|
// Render any child nodes.
|
||||||
switch n.Data {
|
switch n.Data {
|
||||||
case "noembed", "noframes", "noscript", "plaintext", "script", "style":
|
case "iframe", "noembed", "noframes", "noscript", "plaintext", "script", "style":
|
||||||
for _, c := range n.Child {
|
for _, c := range n.Child {
|
||||||
if c.Type != TextNode {
|
if c.Type != TextNode {
|
||||||
return fmt.Errorf("html: raw text element <%s> has non-text child node", n.Data)
|
return fmt.Errorf("html: raw text element <%s> has non-text child node", n.Data)
|
||||||
|
@ -405,14 +405,13 @@ func (z *Tokenizer) readStartTag() TokenType {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Any "<noembed>", "<noframes>", "<noscript>", "<plaintext", "<script>", "<style>",
|
// Several tags flag the tokenizer's next token as raw.
|
||||||
// "<textarea>" or "<title>" tag flags the tokenizer's next token as raw.
|
|
||||||
// The tag name lengths of these special cases ranges in [5, 9].
|
// The tag name lengths of these special cases ranges in [5, 9].
|
||||||
if x := z.data.end - z.data.start; 5 <= x && x <= 9 {
|
if x := z.data.end - z.data.start; 5 <= x && x <= 9 {
|
||||||
switch z.buf[z.data.start] {
|
switch z.buf[z.data.start] {
|
||||||
case 'n', 'p', 's', 't', 'N', 'P', 'S', 'T':
|
case 'i', 'n', 'p', 's', 't', 'I', 'N', 'P', 'S', 'T':
|
||||||
switch s := strings.ToLower(string(z.buf[z.data.start:z.data.end])); s {
|
switch s := strings.ToLower(string(z.buf[z.data.start:z.data.end])); s {
|
||||||
case "noembed", "noframes", "noscript", "plaintext", "script", "style", "textarea", "title":
|
case "iframe", "noembed", "noframes", "noscript", "plaintext", "script", "style", "textarea", "title":
|
||||||
z.rawTag = s
|
z.rawTag = s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user