Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(html/parser): parsing CDATA in svg context #6620

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 1 addition & 6 deletions crates/swc_html_parser/src/parser/mod.rs
Expand Up @@ -533,12 +533,7 @@ where
fn run(&mut self) -> PResult<()> {
while !self.stopped {
let adjusted_current_node = self.get_adjusted_current_node();
let is_element_in_html_namespace =
if is_element_in_html_namespace(adjusted_current_node) {
true
} else {
is_html_integration_point(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);
Expand Down
Expand Up @@ -63,16 +63,15 @@
| <svg foreignObject>
| height="100px"
| width="100px"
| <!-- [CDATA[content]] -->
| "a"
| "contenta"
| "
"
| <svg desc>
| <!-- [CDATA[content]] -->
| "content"
| "
"
| <svg title>
| <!-- [CDATA[content]] -->
| "content"
| "
"
| "
Expand Down
32 changes: 11 additions & 21 deletions crates/swc_html_parser/tests/recovery/text/cdata/output.json
Expand Up @@ -577,25 +577,15 @@
}
],
"children": [
{
"type": "Comment",
"span": {
"start": 485,
"end": 504,
"ctxt": 0
},
"data": "[CDATA[content]]",
"raw": "<![CDATA[content]]>"
},
{
"type": "Text",
"span": {
"start": 504,
"start": 485,
"end": 505,
"ctxt": 0
},
"data": "a",
"raw": "a"
"data": "contenta",
"raw": "contenta"
}
],
"content": null,
Expand Down Expand Up @@ -623,14 +613,14 @@
"attributes": [],
"children": [
{
"type": "Comment",
"type": "Text",
"span": {
"start": 532,
"end": 551,
"end": 548,
"ctxt": 0
},
"data": "[CDATA[content]]",
"raw": "<![CDATA[content]]>"
"data": "content",
"raw": "content"
}
],
"content": null,
Expand Down Expand Up @@ -658,14 +648,14 @@
"attributes": [],
"children": [
{
"type": "Comment",
"type": "Text",
"span": {
"start": 570,
"end": 589,
"end": 586,
"ctxt": 0
},
"data": "[CDATA[content]]",
"raw": "<![CDATA[content]]>"
"data": "content",
"raw": "content"
}
],
"content": null,
Expand Down
24 changes: 0 additions & 24 deletions crates/swc_html_parser/tests/recovery/text/cdata/output.stderr
Expand Up @@ -86,27 +86,3 @@
: ^
18 | <svg viewBox="0 0 100 100">
`----

x Cdata in html content
,-[$DIR/tests/recovery/text/cdata/input.html:18:1]
18 | <svg viewBox="0 0 100 100">
19 | <foreignObject width="100px" height="100px"><![CDATA[content]]>a</foreignObject>
: ^
20 | <desc><![CDATA[content]]></desc>
`----

x Cdata in html content
,-[$DIR/tests/recovery/text/cdata/input.html:19:1]
19 | <foreignObject width="100px" height="100px"><![CDATA[content]]>a</foreignObject>
20 | <desc><![CDATA[content]]></desc>
: ^
21 | <title><![CDATA[content]]></title>
`----

x Cdata in html content
,-[$DIR/tests/recovery/text/cdata/input.html:20:1]
20 | <desc><![CDATA[content]]></desc>
21 | <title><![CDATA[content]]></title>
: ^
22 | </svg>
`----
Expand Up @@ -889,31 +889,15 @@
,-[$DIR/tests/recovery/text/cdata/input.html:18:1]
18 | <svg viewBox="0 0 100 100">
19 | <foreignObject width="100px" height="100px"><![CDATA[content]]>a</foreignObject>
: ^^^^^^^^^^^^^^^^^^^
20 | <desc><![CDATA[content]]></desc>
`----

x Comment
,-[$DIR/tests/recovery/text/cdata/input.html:18:1]
18 | <svg viewBox="0 0 100 100">
19 | <foreignObject width="100px" height="100px"><![CDATA[content]]>a</foreignObject>
: ^^^^^^^^^^^^^^^^^^^
20 | <desc><![CDATA[content]]></desc>
`----

x Child
,-[$DIR/tests/recovery/text/cdata/input.html:18:1]
18 | <svg viewBox="0 0 100 100">
19 | <foreignObject width="100px" height="100px"><![CDATA[content]]>a</foreignObject>
: ^
: ^^^^^^^^^^^^^^^^^^^^
20 | <desc><![CDATA[content]]></desc>
`----

x Text
,-[$DIR/tests/recovery/text/cdata/input.html:18:1]
18 | <svg viewBox="0 0 100 100">
19 | <foreignObject width="100px" height="100px"><![CDATA[content]]>a</foreignObject>
: ^
: ^^^^^^^^^^^^^^^^^^^^
20 | <desc><![CDATA[content]]></desc>
`----

Expand Down Expand Up @@ -953,15 +937,15 @@
,-[$DIR/tests/recovery/text/cdata/input.html:19:1]
19 | <foreignObject width="100px" height="100px"><![CDATA[content]]>a</foreignObject>
20 | <desc><![CDATA[content]]></desc>
: ^^^^^^^^^^^^^^^^^^^
: ^^^^^^^^^^^^^^^^
21 | <title><![CDATA[content]]></title>
`----

x Comment
x Text
,-[$DIR/tests/recovery/text/cdata/input.html:19:1]
19 | <foreignObject width="100px" height="100px"><![CDATA[content]]>a</foreignObject>
20 | <desc><![CDATA[content]]></desc>
: ^^^^^^^^^^^^^^^^^^^
: ^^^^^^^^^^^^^^^^
21 | <title><![CDATA[content]]></title>
`----

Expand Down Expand Up @@ -1001,15 +985,15 @@
,-[$DIR/tests/recovery/text/cdata/input.html:20:1]
20 | <desc><![CDATA[content]]></desc>
21 | <title><![CDATA[content]]></title>
: ^^^^^^^^^^^^^^^^^^^
: ^^^^^^^^^^^^^^^^
22 | </svg>
`----

x Comment
x Text
,-[$DIR/tests/recovery/text/cdata/input.html:20:1]
20 | <desc><![CDATA[content]]></desc>
21 | <title><![CDATA[content]]></title>
: ^^^^^^^^^^^^^^^^^^^
: ^^^^^^^^^^^^^^^^
22 | </svg>
`----

Expand Down