fix(html/parser): Fix parsing of cdata (#4537)

This commit is contained in:
Alexander Akait 2022-05-06 09:12:46 +03:00 committed by GitHub
parent f552c1c11d
commit 07cf28a168
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 158 additions and 22 deletions

View File

@ -155,6 +155,12 @@ where
})));
while !self.stopped {
let adjusted_current_node = self.get_adjusted_current_node();
let is_element_in_html_namespace = is_element_in_html_namespace(adjusted_current_node);
self.input
.set_adjusted_current_node_to_html_namespace(is_element_in_html_namespace);
let span = self.input.cur_span()?;
let token = match self.input.cur()? {
Some(_) => {

View File

@ -2,7 +2,7 @@
"type": "Document",
"span": {
"start": 0,
"end": 36,
"end": 39,
"ctxt": 0
},
"mode": "no-quirks",
@ -22,7 +22,7 @@
"type": "Element",
"span": {
"start": 0,
"end": 36,
"end": 39,
"ctxt": 0
},
"tagName": "html",
@ -46,7 +46,7 @@
"type": "Element",
"span": {
"start": 0,
"end": 36,
"end": 39,
"ctxt": 0
},
"tagName": "body",
@ -67,13 +67,13 @@
"content": null
},
{
"type": "Text",
"type": "Comment",
"span": {
"start": 26,
"end": 36,
"end": 39,
"ctxt": 0
},
"value": "a"
"data": "[CDATA[a]]"
}
],
"content": null

View File

@ -2,7 +2,7 @@
"type": "Document",
"span": {
"start": 0,
"end": 37,
"end": 40,
"ctxt": 0
},
"mode": "no-quirks",
@ -11,7 +11,7 @@
"type": "Element",
"span": {
"start": 0,
"end": 37,
"end": 40,
"ctxt": 0
},
"tagName": "html",
@ -35,7 +35,7 @@
"type": "Element",
"span": {
"start": 0,
"end": 37,
"end": 40,
"ctxt": 0
},
"tagName": "body",
@ -46,7 +46,7 @@
"type": "Element",
"span": {
"start": 0,
"end": 37,
"end": 40,
"ctxt": 0
},
"tagName": "svg",
@ -57,7 +57,7 @@
"type": "Element",
"span": {
"start": 5,
"end": 37,
"end": 40,
"ctxt": 0
},
"tagName": "foreignObject",
@ -68,7 +68,7 @@
"type": "Element",
"span": {
"start": 20,
"end": 37,
"end": 40,
"ctxt": 0
},
"tagName": "div",
@ -76,13 +76,13 @@
"attributes": [],
"children": [
{
"type": "Text",
"type": "Comment",
"span": {
"start": 25,
"end": 37,
"end": 40,
"ctxt": 0
},
"value": "foo"
"data": "[CDATA[foo]]"
}
],
"content": null

View File

@ -2,7 +2,7 @@
"type": "Document",
"span": {
"start": 0,
"end": 17,
"end": 20,
"ctxt": 0
},
"mode": "no-quirks",
@ -11,7 +11,7 @@
"type": "Element",
"span": {
"start": 0,
"end": 17,
"end": 20,
"ctxt": 0
},
"tagName": "html",
@ -35,7 +35,7 @@
"type": "Element",
"span": {
"start": 0,
"end": 17,
"end": 20,
"ctxt": 0
},
"tagName": "body",
@ -46,7 +46,7 @@
"type": "Element",
"span": {
"start": 0,
"end": 17,
"end": 20,
"ctxt": 0
},
"tagName": "div",
@ -54,13 +54,13 @@
"attributes": [],
"children": [
{
"type": "Text",
"type": "Comment",
"span": {
"start": 5,
"end": 17,
"end": 20,
"ctxt": 0
},
"value": "foo"
"data": "[CDATA[foo]]"
}
],
"content": null

View File

@ -0,0 +1 @@
<div><![CDATA[foo]]>

View File

@ -0,0 +1,75 @@
{
"type": "Document",
"span": {
"start": 0,
"end": 20,
"ctxt": 0
},
"mode": "no-quirks",
"children": [
{
"type": "Element",
"span": {
"start": 0,
"end": 20,
"ctxt": 0
},
"tagName": "html",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [
{
"type": "Element",
"span": {
"start": 0,
"end": 5,
"ctxt": 0
},
"tagName": "head",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [],
"content": null
},
{
"type": "Element",
"span": {
"start": 0,
"end": 20,
"ctxt": 0
},
"tagName": "body",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [
{
"type": "Element",
"span": {
"start": 0,
"end": 20,
"ctxt": 0
},
"tagName": "div",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [
{
"type": "Comment",
"span": {
"start": 5,
"end": 20,
"ctxt": 0
},
"data": "[CDATA[foo]]"
}
],
"content": null
}
],
"content": null
}
],
"content": null
}
]
}

View File

@ -0,0 +1,12 @@
x Cdata in html content
,-[$DIR/tests/recovery/comment/cdata-2/input.html:1:1]
1 | <div><![CDATA[foo]]>
: ^^^^^^^^^
`----
x Unexpected token
,-[$DIR/tests/recovery/comment/cdata-2/input.html:1:1]
1 | <div><![CDATA[foo]]>
: ^^^^^^^^^^^^^^^^^^^^
`----

View File

@ -0,0 +1,42 @@
x Document
,-[$DIR/tests/recovery/comment/cdata-2/input.html:1:1]
1 | <div><![CDATA[foo]]>
: ^^^^^^^^^^^^^^^^^^^^
`----
x Child
,-[$DIR/tests/recovery/comment/cdata-2/input.html:1:1]
1 | <div><![CDATA[foo]]>
: ^^^^^^^^^^^^^^^^^^^^
`----
x Element
,-[$DIR/tests/recovery/comment/cdata-2/input.html:1:1]
1 | <div><![CDATA[foo]]>
: ^^^^^^^^^^^^^^^^^^^^
`----
x Child
,-[$DIR/tests/recovery/comment/cdata-2/input.html:1:1]
1 | <div><![CDATA[foo]]>
: ^^^^^
`----
x Element
,-[$DIR/tests/recovery/comment/cdata-2/input.html:1:1]
1 | <div><![CDATA[foo]]>
: ^^^^^
`----
x Child
,-[$DIR/tests/recovery/comment/cdata-2/input.html:1:1]
1 | <div><![CDATA[foo]]>
: ^^^^^^^^^^^^^^^
`----
x Comment
,-[$DIR/tests/recovery/comment/cdata-2/input.html:1:1]
1 | <div><![CDATA[foo]]>
: ^^^^^^^^^^^^^^^
`----