mirror of
https://github.com/swc-project/swc.git
synced 2024-12-24 06:05:02 +03:00
fix(html/parser): Fix parsing of cdata (#6534)
This commit is contained in:
parent
5a9aab2392
commit
e3cbe7e9a9
11
crates/swc_html_codegen/tests/fixture/cdata/input.html
Normal file
11
crates/swc_html_codegen/tests/fixture/cdata/input.html
Normal file
@ -0,0 +1,11 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
<svg viewBox="0 0 100 100">
|
||||
<text><![CDATA[content]]></text>
|
||||
</svg>
|
||||
</body>
|
||||
</html>
|
11
crates/swc_html_codegen/tests/fixture/cdata/output.html
Normal file
11
crates/swc_html_codegen/tests/fixture/cdata/output.html
Normal file
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
<svg viewBox="0 0 100 100">
|
||||
<text>content</text>
|
||||
</svg>
|
||||
|
||||
</body></html>
|
@ -0,0 +1,8 @@
|
||||
<!doctype html><html lang=en><head>
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
<svg viewBox="0 0 100 100">
|
||||
<text>content</text>
|
||||
</svg>
|
||||
|
@ -134,8 +134,6 @@ struct Comment {
|
||||
|
||||
pub(crate) type LexResult<T> = Result<T, ErrorKind>;
|
||||
|
||||
// TODO improve `raw` for all tokens (linting + better codegen)
|
||||
|
||||
pub struct Lexer<I>
|
||||
where
|
||||
I: Input,
|
||||
@ -2682,37 +2680,35 @@ where
|
||||
// error. Create a comment token whose data is the "[CDATA[" string.
|
||||
// Switch to the bogus comment state.
|
||||
Some('[') => match self.consume_next_char() {
|
||||
Some(c @ 'c' | c @ 'C') => match self.consume_next_char() {
|
||||
Some(d @ 'd' | d @ 'D') => match self.consume_next_char() {
|
||||
Some(a1 @ 'a' | a1 @ 'A') => match self.consume_next_char() {
|
||||
Some(t @ 't' | t @ 'T') => match self.consume_next_char() {
|
||||
Some(a2 @ 'a' | a2 @ 'A') => {
|
||||
match self.consume_next_char() {
|
||||
Some('[') => {
|
||||
if let Some(false) = self.is_adjusted_current_node_is_element_in_html_namespace {
|
||||
self.state = State::CdataSection;
|
||||
} else {
|
||||
self.emit_error(
|
||||
ErrorKind::CdataInHtmlContent,
|
||||
);
|
||||
let mut data = String::with_capacity(7);
|
||||
Some(c @ 'C') => match self.consume_next_char() {
|
||||
Some(d @ 'D') => match self.consume_next_char() {
|
||||
Some(a1 @ 'A') => match self.consume_next_char() {
|
||||
Some(t @ 'T') => match self.consume_next_char() {
|
||||
Some(a2 @ 'A') => match self.consume_next_char() {
|
||||
Some('[') => {
|
||||
if let Some(false) = self.is_adjusted_current_node_is_element_in_html_namespace {
|
||||
self.state = State::CdataSection;
|
||||
} else {
|
||||
self.emit_error(
|
||||
ErrorKind::CdataInHtmlContent,
|
||||
);
|
||||
let mut data = String::with_capacity(7);
|
||||
|
||||
data.push('[');
|
||||
data.push(c);
|
||||
data.push(d);
|
||||
data.push(a1);
|
||||
data.push(t);
|
||||
data.push(a2);
|
||||
data.push('[');
|
||||
data.push('[');
|
||||
data.push(c);
|
||||
data.push(d);
|
||||
data.push(a1);
|
||||
data.push(t);
|
||||
data.push(a2);
|
||||
data.push('[');
|
||||
|
||||
self.create_comment_token(Some(data), "<!");
|
||||
self.state = State::BogusComment;
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
anything_else(self);
|
||||
self.create_comment_token(Some(data), "<!");
|
||||
self.state = State::BogusComment;
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
anything_else(self);
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
anything_else(self);
|
||||
@ -2725,15 +2721,15 @@ where
|
||||
_ => {
|
||||
anything_else(self);
|
||||
}
|
||||
},
|
||||
}
|
||||
_ => {
|
||||
anything_else(self);
|
||||
}
|
||||
},
|
||||
}
|
||||
_ => {
|
||||
anything_else(self);
|
||||
}
|
||||
},
|
||||
}
|
||||
// Anything else
|
||||
// This is an incorrectly-opened-comment parse error. Create a comment token
|
||||
// whose data is the empty string. Switch to the bogus comment state (don't
|
||||
|
@ -508,7 +508,7 @@ where
|
||||
}
|
||||
Data::Text { data, raw } => {
|
||||
let span = if let Some(end_span) = node.end_span.take() {
|
||||
swc_common::Span::new(start_span.lo(), end_span.hi(), Default::default())
|
||||
Span::new(start_span.lo(), end_span.hi(), Default::default())
|
||||
} else {
|
||||
start_span
|
||||
};
|
||||
@ -533,7 +533,12 @@ where
|
||||
fn run(&mut self) -> PResult<()> {
|
||||
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);
|
||||
let is_element_in_html_namespace =
|
||||
if is_element_in_html_namespace(adjusted_current_node) {
|
||||
true
|
||||
} else {
|
||||
is_html_integration_point(adjusted_current_node)
|
||||
};
|
||||
|
||||
self.input
|
||||
.set_adjusted_current_node_to_html_namespace(is_element_in_html_namespace);
|
||||
@ -625,9 +630,6 @@ where
|
||||
let is_mathml_annotation_xml = is_mathml_annotation_xml(adjusted_current_node);
|
||||
let is_html_integration_point = is_html_integration_point(adjusted_current_node);
|
||||
|
||||
self.input
|
||||
.set_adjusted_current_node_to_html_namespace(is_element_in_html_namespace);
|
||||
|
||||
if self.open_elements_stack.items.is_empty()
|
||||
|| is_element_in_html_namespace
|
||||
|| (is_mathml_text_integration_point
|
||||
|
@ -0,0 +1,112 @@
|
||||
| <!DOCTYPE html>
|
||||
| <html>
|
||||
| lang="en-US"
|
||||
| <head>
|
||||
| "
|
||||
"
|
||||
| <meta>
|
||||
| charset="utf-8"
|
||||
| "
|
||||
"
|
||||
| <title>
|
||||
| "SVG Demo"
|
||||
| "
|
||||
"
|
||||
| <meta>
|
||||
| content="width=device-width"
|
||||
| name="viewport"
|
||||
| "
|
||||
"
|
||||
| "
|
||||
"
|
||||
| <body>
|
||||
| "
|
||||
"
|
||||
| <svg svg>
|
||||
| viewBox="0 0 100 100"
|
||||
| "
|
||||
"
|
||||
| <svg title>
|
||||
| "A gradient"
|
||||
| "
|
||||
"
|
||||
| <svg linearGradient>
|
||||
| id="gradient"
|
||||
| "
|
||||
"
|
||||
| <svg stop>
|
||||
| class="begin"
|
||||
| offset="0%"
|
||||
| "
|
||||
"
|
||||
| <svg stop>
|
||||
| class="end"
|
||||
| offset="100%"
|
||||
| "
|
||||
"
|
||||
| "
|
||||
"
|
||||
| <svg rect>
|
||||
| height="100"
|
||||
| style="fill:url(#gradient)"
|
||||
| width="100"
|
||||
| x="0"
|
||||
| y="0"
|
||||
| "
|
||||
"
|
||||
| <svg circle>
|
||||
| cx="50"
|
||||
| cy="50"
|
||||
| r="30"
|
||||
| style="fill:url(#gradient)"
|
||||
| "
|
||||
"
|
||||
| <svg text>
|
||||
| class="empty"
|
||||
| "
|
||||
"
|
||||
| <svg text>
|
||||
| "content"
|
||||
| "
|
||||
"
|
||||
| <svg text>
|
||||
| "&ing"
|
||||
| "
|
||||
"
|
||||
| <svg text>
|
||||
| "&ing ]"
|
||||
| "
|
||||
"
|
||||
| <svg text>
|
||||
| "&ing]] "
|
||||
| "
|
||||
"
|
||||
| <svg text>
|
||||
| "<message>text</message>"
|
||||
| "
|
||||
"
|
||||
| <svg text>
|
||||
| "</this is malformed!</malformed</malformed & worse>"
|
||||
| "
|
||||
"
|
||||
| <svg text>
|
||||
| "12"
|
||||
| "
|
||||
"
|
||||
| <svg text>
|
||||
| "
|
||||
data
|
||||
"
|
||||
| "
|
||||
"
|
||||
| <svg text>
|
||||
| "bracket ]after"
|
||||
| "
|
||||
"
|
||||
| <svg text>
|
||||
| "abracket ]afterb"
|
||||
| "
|
||||
"
|
||||
| "
|
||||
|
||||
"
|
@ -0,0 +1,32 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en-US">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>SVG Demo</title>
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
</head>
|
||||
<body>
|
||||
<svg viewBox="0 0 100 100">
|
||||
<title>A gradient</title>
|
||||
<linearGradient id="gradient">
|
||||
<stop class="begin" offset="0%" />
|
||||
<stop class="end" offset="100%" />
|
||||
</linearGradient>
|
||||
<rect x="0" y="0" width="100" height="100" style="fill:url(#gradient)" />
|
||||
<circle cx="50" cy="50" r="30" style="fill:url(#gradient)" />
|
||||
<text class="empty"><![CDATA[]]></text>
|
||||
<text><![CDATA[content]]></text>
|
||||
<text><![CDATA[&ing]]></text>
|
||||
<text><![CDATA[&ing ]]]></text>
|
||||
<text><![CDATA[&ing]] ]]></text>
|
||||
<text><![CDATA[<message>text</message>]]></text>
|
||||
<text><![CDATA[</this is malformed!</malformed</malformed & worse>]]></text>
|
||||
<text><![CDATA[1]]><![CDATA[2]]></text>
|
||||
<text>
|
||||
<![CDATA[data]]>
|
||||
</text>
|
||||
<text><![CDATA[bracket ]after]]></text>
|
||||
<text>a<![CDATA[bracket ]after]]>b</text>
|
||||
</svg>
|
||||
</body>
|
||||
</html>
|
1046
crates/swc_html_parser/tests/fixture/text/cdata-svg/output.json
Normal file
1046
crates/swc_html_parser/tests/fixture/text/cdata-svg/output.json
Normal file
File diff suppressed because it is too large
Load Diff
1364
crates/swc_html_parser/tests/fixture/text/cdata-svg/span.rust-debug
Normal file
1364
crates/swc_html_parser/tests/fixture/text/cdata-svg/span.rust-debug
Normal file
File diff suppressed because it is too large
Load Diff
@ -14,10 +14,10 @@
|
||||
10 | <![cdata[
|
||||
`----
|
||||
|
||||
x Cdata in html content
|
||||
x Incorrectly opened comment
|
||||
,-[$DIR/tests/recovery/comment/cdata-1/input.html:9:1]
|
||||
9 | <div>test</div>
|
||||
10 | <![cdata[
|
||||
: ^
|
||||
: ^
|
||||
11 | Within this Character Data block I can
|
||||
`----
|
||||
|
@ -0,0 +1,80 @@
|
||||
| <!DOCTYPE html>
|
||||
| <html>
|
||||
| lang="en"
|
||||
| <head>
|
||||
| "
|
||||
"
|
||||
| <title>
|
||||
| "Document"
|
||||
| "
|
||||
"
|
||||
| "
|
||||
"
|
||||
| <body>
|
||||
| "
|
||||
"
|
||||
| <p>
|
||||
| <!-- [CDATA[content]] -->
|
||||
| "
|
||||
"
|
||||
| <p>
|
||||
| <!-- [CDATA[&ing]] -->
|
||||
| "
|
||||
"
|
||||
| <p>
|
||||
| <!-- [CDATA[&ing ]]] -->
|
||||
| "
|
||||
"
|
||||
| <p>
|
||||
| <!-- [CDATA[&ing]] ]] -->
|
||||
| "
|
||||
"
|
||||
| <p>
|
||||
| <!-- [CDATA[<message -->
|
||||
| "text]]>"
|
||||
| "
|
||||
"
|
||||
| <p>
|
||||
| <!-- [CDATA[</this is malformed!</malformed</malformed & worse -->
|
||||
| "]]>"
|
||||
| "
|
||||
"
|
||||
| <p>
|
||||
| <!-- [CDATA[1]] -->
|
||||
| <!-- [CDATA[2]] -->
|
||||
| "
|
||||
"
|
||||
| <p>
|
||||
| "
|
||||
"
|
||||
| <!-- [CDATA[data]] -->
|
||||
| "
|
||||
"
|
||||
| "
|
||||
"
|
||||
| <p>
|
||||
| <!-- [CDATA[bracket ]after]] -->
|
||||
| "
|
||||
"
|
||||
| <svg svg>
|
||||
| viewBox="0 0 100 100"
|
||||
| "
|
||||
"
|
||||
| <svg foreignObject>
|
||||
| height="100px"
|
||||
| width="100px"
|
||||
| <!-- [CDATA[content]] -->
|
||||
| "a"
|
||||
| "
|
||||
"
|
||||
| <svg desc>
|
||||
| <!-- [CDATA[content]] -->
|
||||
| "
|
||||
"
|
||||
| <svg title>
|
||||
| <!-- [CDATA[content]] -->
|
||||
| "
|
||||
"
|
||||
| "
|
||||
|
||||
"
|
24
crates/swc_html_parser/tests/recovery/text/cdata/input.html
Normal file
24
crates/swc_html_parser/tests/recovery/text/cdata/input.html
Normal file
@ -0,0 +1,24 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
<p><![CDATA[content]]></p>
|
||||
<p><![CDATA[&ing]]></p>
|
||||
<p><![CDATA[&ing ]]]></p>
|
||||
<p><![CDATA[&ing]] ]]></p>
|
||||
<p><![CDATA[<message>text</message>]]></p>
|
||||
<p><![CDATA[</this is malformed!</malformed</malformed & worse>]]></p>
|
||||
<p><![CDATA[1]]><![CDATA[2]]></p>
|
||||
<p>
|
||||
<![CDATA[data]]>
|
||||
</p>
|
||||
<p><![CDATA[bracket ]after]]></p>
|
||||
<svg viewBox="0 0 100 100">
|
||||
<foreignObject width="100px" height="100px"><![CDATA[content]]>a</foreignObject>
|
||||
<desc><![CDATA[content]]></desc>
|
||||
<title><![CDATA[content]]></title>
|
||||
</svg>
|
||||
</body>
|
||||
</html>
|
707
crates/swc_html_parser/tests/recovery/text/cdata/output.json
Normal file
707
crates/swc_html_parser/tests/recovery/text/cdata/output.json
Normal file
@ -0,0 +1,707 @@
|
||||
{
|
||||
"type": "Document",
|
||||
"span": {
|
||||
"start": 1,
|
||||
"end": 620,
|
||||
"ctxt": 0
|
||||
},
|
||||
"mode": "no-quirks",
|
||||
"children": [
|
||||
{
|
||||
"type": "DocumentType",
|
||||
"span": {
|
||||
"start": 1,
|
||||
"end": 16,
|
||||
"ctxt": 0
|
||||
},
|
||||
"name": "html",
|
||||
"publicId": null,
|
||||
"systemId": null,
|
||||
"raw": "<!doctype html>"
|
||||
},
|
||||
{
|
||||
"type": "Element",
|
||||
"span": {
|
||||
"start": 17,
|
||||
"end": 620,
|
||||
"ctxt": 0
|
||||
},
|
||||
"tagName": "html",
|
||||
"namespace": "http://www.w3.org/1999/xhtml",
|
||||
"attributes": [
|
||||
{
|
||||
"type": "Attribute",
|
||||
"span": {
|
||||
"start": 23,
|
||||
"end": 32,
|
||||
"ctxt": 0
|
||||
},
|
||||
"namespace": null,
|
||||
"prefix": null,
|
||||
"name": "lang",
|
||||
"rawName": "lang",
|
||||
"value": "en",
|
||||
"rawValue": "\"en\""
|
||||
}
|
||||
],
|
||||
"children": [
|
||||
{
|
||||
"type": "Element",
|
||||
"span": {
|
||||
"start": 34,
|
||||
"end": 76,
|
||||
"ctxt": 0
|
||||
},
|
||||
"tagName": "head",
|
||||
"namespace": "http://www.w3.org/1999/xhtml",
|
||||
"attributes": [],
|
||||
"children": [
|
||||
{
|
||||
"type": "Text",
|
||||
"span": {
|
||||
"start": 40,
|
||||
"end": 45,
|
||||
"ctxt": 0
|
||||
},
|
||||
"data": "\n ",
|
||||
"raw": "\n "
|
||||
},
|
||||
{
|
||||
"type": "Element",
|
||||
"span": {
|
||||
"start": 45,
|
||||
"end": 68,
|
||||
"ctxt": 0
|
||||
},
|
||||
"tagName": "title",
|
||||
"namespace": "http://www.w3.org/1999/xhtml",
|
||||
"attributes": [],
|
||||
"children": [
|
||||
{
|
||||
"type": "Text",
|
||||
"span": {
|
||||
"start": 52,
|
||||
"end": 60,
|
||||
"ctxt": 0
|
||||
},
|
||||
"data": "Document",
|
||||
"raw": "Document"
|
||||
}
|
||||
],
|
||||
"content": null,
|
||||
"isSelfClosing": false
|
||||
},
|
||||
{
|
||||
"type": "Text",
|
||||
"span": {
|
||||
"start": 68,
|
||||
"end": 69,
|
||||
"ctxt": 0
|
||||
},
|
||||
"data": "\n",
|
||||
"raw": "\n"
|
||||
}
|
||||
],
|
||||
"content": null,
|
||||
"isSelfClosing": false
|
||||
},
|
||||
{
|
||||
"type": "Text",
|
||||
"span": {
|
||||
"start": 76,
|
||||
"end": 77,
|
||||
"ctxt": 0
|
||||
},
|
||||
"data": "\n",
|
||||
"raw": "\n"
|
||||
},
|
||||
{
|
||||
"type": "Element",
|
||||
"span": {
|
||||
"start": 77,
|
||||
"end": 613,
|
||||
"ctxt": 0
|
||||
},
|
||||
"tagName": "body",
|
||||
"namespace": "http://www.w3.org/1999/xhtml",
|
||||
"attributes": [],
|
||||
"children": [
|
||||
{
|
||||
"type": "Text",
|
||||
"span": {
|
||||
"start": 83,
|
||||
"end": 84,
|
||||
"ctxt": 0
|
||||
},
|
||||
"data": "\n",
|
||||
"raw": "\n"
|
||||
},
|
||||
{
|
||||
"type": "Element",
|
||||
"span": {
|
||||
"start": 84,
|
||||
"end": 110,
|
||||
"ctxt": 0
|
||||
},
|
||||
"tagName": "p",
|
||||
"namespace": "http://www.w3.org/1999/xhtml",
|
||||
"attributes": [],
|
||||
"children": [
|
||||
{
|
||||
"type": "Comment",
|
||||
"span": {
|
||||
"start": 87,
|
||||
"end": 106,
|
||||
"ctxt": 0
|
||||
},
|
||||
"data": "[CDATA[content]]",
|
||||
"raw": "<![CDATA[content]]>"
|
||||
}
|
||||
],
|
||||
"content": null,
|
||||
"isSelfClosing": false
|
||||
},
|
||||
{
|
||||
"type": "Text",
|
||||
"span": {
|
||||
"start": 110,
|
||||
"end": 111,
|
||||
"ctxt": 0
|
||||
},
|
||||
"data": "\n",
|
||||
"raw": "\n"
|
||||
},
|
||||
{
|
||||
"type": "Element",
|
||||
"span": {
|
||||
"start": 111,
|
||||
"end": 137,
|
||||
"ctxt": 0
|
||||
},
|
||||
"tagName": "p",
|
||||
"namespace": "http://www.w3.org/1999/xhtml",
|
||||
"attributes": [],
|
||||
"children": [
|
||||
{
|
||||
"type": "Comment",
|
||||
"span": {
|
||||
"start": 114,
|
||||
"end": 133,
|
||||
"ctxt": 0
|
||||
},
|
||||
"data": "[CDATA[&ing]]",
|
||||
"raw": "<![CDATA[&ing]]>"
|
||||
}
|
||||
],
|
||||
"content": null,
|
||||
"isSelfClosing": false
|
||||
},
|
||||
{
|
||||
"type": "Text",
|
||||
"span": {
|
||||
"start": 137,
|
||||
"end": 138,
|
||||
"ctxt": 0
|
||||
},
|
||||
"data": "\n",
|
||||
"raw": "\n"
|
||||
},
|
||||
{
|
||||
"type": "Element",
|
||||
"span": {
|
||||
"start": 138,
|
||||
"end": 166,
|
||||
"ctxt": 0
|
||||
},
|
||||
"tagName": "p",
|
||||
"namespace": "http://www.w3.org/1999/xhtml",
|
||||
"attributes": [],
|
||||
"children": [
|
||||
{
|
||||
"type": "Comment",
|
||||
"span": {
|
||||
"start": 141,
|
||||
"end": 162,
|
||||
"ctxt": 0
|
||||
},
|
||||
"data": "[CDATA[&ing ]]]",
|
||||
"raw": "<![CDATA[&ing ]]]>"
|
||||
}
|
||||
],
|
||||
"content": null,
|
||||
"isSelfClosing": false
|
||||
},
|
||||
{
|
||||
"type": "Text",
|
||||
"span": {
|
||||
"start": 166,
|
||||
"end": 167,
|
||||
"ctxt": 0
|
||||
},
|
||||
"data": "\n",
|
||||
"raw": "\n"
|
||||
},
|
||||
{
|
||||
"type": "Element",
|
||||
"span": {
|
||||
"start": 167,
|
||||
"end": 196,
|
||||
"ctxt": 0
|
||||
},
|
||||
"tagName": "p",
|
||||
"namespace": "http://www.w3.org/1999/xhtml",
|
||||
"attributes": [],
|
||||
"children": [
|
||||
{
|
||||
"type": "Comment",
|
||||
"span": {
|
||||
"start": 170,
|
||||
"end": 192,
|
||||
"ctxt": 0
|
||||
},
|
||||
"data": "[CDATA[&ing]] ]]",
|
||||
"raw": "<![CDATA[&ing]] ]]>"
|
||||
}
|
||||
],
|
||||
"content": null,
|
||||
"isSelfClosing": false
|
||||
},
|
||||
{
|
||||
"type": "Text",
|
||||
"span": {
|
||||
"start": 196,
|
||||
"end": 197,
|
||||
"ctxt": 0
|
||||
},
|
||||
"data": "\n",
|
||||
"raw": "\n"
|
||||
},
|
||||
{
|
||||
"type": "Element",
|
||||
"span": {
|
||||
"start": 197,
|
||||
"end": 239,
|
||||
"ctxt": 0
|
||||
},
|
||||
"tagName": "p",
|
||||
"namespace": "http://www.w3.org/1999/xhtml",
|
||||
"attributes": [],
|
||||
"children": [
|
||||
{
|
||||
"type": "Comment",
|
||||
"span": {
|
||||
"start": 200,
|
||||
"end": 218,
|
||||
"ctxt": 0
|
||||
},
|
||||
"data": "[CDATA[<message",
|
||||
"raw": "<![CDATA[<message>"
|
||||
},
|
||||
{
|
||||
"type": "Text",
|
||||
"span": {
|
||||
"start": 218,
|
||||
"end": 235,
|
||||
"ctxt": 0
|
||||
},
|
||||
"data": "text]]>",
|
||||
"raw": "text]]>"
|
||||
}
|
||||
],
|
||||
"content": null,
|
||||
"isSelfClosing": false
|
||||
},
|
||||
{
|
||||
"type": "Text",
|
||||
"span": {
|
||||
"start": 239,
|
||||
"end": 240,
|
||||
"ctxt": 0
|
||||
},
|
||||
"data": "\n",
|
||||
"raw": "\n"
|
||||
},
|
||||
{
|
||||
"type": "Element",
|
||||
"span": {
|
||||
"start": 240,
|
||||
"end": 310,
|
||||
"ctxt": 0
|
||||
},
|
||||
"tagName": "p",
|
||||
"namespace": "http://www.w3.org/1999/xhtml",
|
||||
"attributes": [],
|
||||
"children": [
|
||||
{
|
||||
"type": "Comment",
|
||||
"span": {
|
||||
"start": 243,
|
||||
"end": 303,
|
||||
"ctxt": 0
|
||||
},
|
||||
"data": "[CDATA[</this is malformed!</malformed</malformed & worse",
|
||||
"raw": "<![CDATA[</this is malformed!</malformed</malformed & worse>"
|
||||
},
|
||||
{
|
||||
"type": "Text",
|
||||
"span": {
|
||||
"start": 303,
|
||||
"end": 306,
|
||||
"ctxt": 0
|
||||
},
|
||||
"data": "]]>",
|
||||
"raw": "]]>"
|
||||
}
|
||||
],
|
||||
"content": null,
|
||||
"isSelfClosing": false
|
||||
},
|
||||
{
|
||||
"type": "Text",
|
||||
"span": {
|
||||
"start": 310,
|
||||
"end": 311,
|
||||
"ctxt": 0
|
||||
},
|
||||
"data": "\n",
|
||||
"raw": "\n"
|
||||
},
|
||||
{
|
||||
"type": "Element",
|
||||
"span": {
|
||||
"start": 311,
|
||||
"end": 344,
|
||||
"ctxt": 0
|
||||
},
|
||||
"tagName": "p",
|
||||
"namespace": "http://www.w3.org/1999/xhtml",
|
||||
"attributes": [],
|
||||
"children": [
|
||||
{
|
||||
"type": "Comment",
|
||||
"span": {
|
||||
"start": 314,
|
||||
"end": 327,
|
||||
"ctxt": 0
|
||||
},
|
||||
"data": "[CDATA[1]]",
|
||||
"raw": "<![CDATA[1]]>"
|
||||
},
|
||||
{
|
||||
"type": "Comment",
|
||||
"span": {
|
||||
"start": 327,
|
||||
"end": 340,
|
||||
"ctxt": 0
|
||||
},
|
||||
"data": "[CDATA[2]]",
|
||||
"raw": "<![CDATA[2]]>"
|
||||
}
|
||||
],
|
||||
"content": null,
|
||||
"isSelfClosing": false
|
||||
},
|
||||
{
|
||||
"type": "Text",
|
||||
"span": {
|
||||
"start": 344,
|
||||
"end": 345,
|
||||
"ctxt": 0
|
||||
},
|
||||
"data": "\n",
|
||||
"raw": "\n"
|
||||
},
|
||||
{
|
||||
"type": "Element",
|
||||
"span": {
|
||||
"start": 345,
|
||||
"end": 374,
|
||||
"ctxt": 0
|
||||
},
|
||||
"tagName": "p",
|
||||
"namespace": "http://www.w3.org/1999/xhtml",
|
||||
"attributes": [],
|
||||
"children": [
|
||||
{
|
||||
"type": "Text",
|
||||
"span": {
|
||||
"start": 348,
|
||||
"end": 353,
|
||||
"ctxt": 0
|
||||
},
|
||||
"data": "\n ",
|
||||
"raw": "\n "
|
||||
},
|
||||
{
|
||||
"type": "Comment",
|
||||
"span": {
|
||||
"start": 353,
|
||||
"end": 369,
|
||||
"ctxt": 0
|
||||
},
|
||||
"data": "[CDATA[data]]",
|
||||
"raw": "<![CDATA[data]]>"
|
||||
},
|
||||
{
|
||||
"type": "Text",
|
||||
"span": {
|
||||
"start": 369,
|
||||
"end": 370,
|
||||
"ctxt": 0
|
||||
},
|
||||
"data": "\n",
|
||||
"raw": "\n"
|
||||
}
|
||||
],
|
||||
"content": null,
|
||||
"isSelfClosing": false
|
||||
},
|
||||
{
|
||||
"type": "Text",
|
||||
"span": {
|
||||
"start": 374,
|
||||
"end": 375,
|
||||
"ctxt": 0
|
||||
},
|
||||
"data": "\n",
|
||||
"raw": "\n"
|
||||
},
|
||||
{
|
||||
"type": "Element",
|
||||
"span": {
|
||||
"start": 375,
|
||||
"end": 408,
|
||||
"ctxt": 0
|
||||
},
|
||||
"tagName": "p",
|
||||
"namespace": "http://www.w3.org/1999/xhtml",
|
||||
"attributes": [],
|
||||
"children": [
|
||||
{
|
||||
"type": "Comment",
|
||||
"span": {
|
||||
"start": 378,
|
||||
"end": 404,
|
||||
"ctxt": 0
|
||||
},
|
||||
"data": "[CDATA[bracket ]after]]",
|
||||
"raw": "<![CDATA[bracket ]after]]>"
|
||||
}
|
||||
],
|
||||
"content": null,
|
||||
"isSelfClosing": false
|
||||
},
|
||||
{
|
||||
"type": "Text",
|
||||
"span": {
|
||||
"start": 408,
|
||||
"end": 409,
|
||||
"ctxt": 0
|
||||
},
|
||||
"data": "\n",
|
||||
"raw": "\n"
|
||||
},
|
||||
{
|
||||
"type": "Element",
|
||||
"span": {
|
||||
"start": 409,
|
||||
"end": 604,
|
||||
"ctxt": 0
|
||||
},
|
||||
"tagName": "svg",
|
||||
"namespace": "http://www.w3.org/2000/svg",
|
||||
"attributes": [
|
||||
{
|
||||
"type": "Attribute",
|
||||
"span": {
|
||||
"start": 414,
|
||||
"end": 435,
|
||||
"ctxt": 0
|
||||
},
|
||||
"namespace": null,
|
||||
"prefix": null,
|
||||
"name": "viewBox",
|
||||
"rawName": "viewBox",
|
||||
"value": "0 0 100 100",
|
||||
"rawValue": "\"0 0 100 100\""
|
||||
}
|
||||
],
|
||||
"children": [
|
||||
{
|
||||
"type": "Text",
|
||||
"span": {
|
||||
"start": 436,
|
||||
"end": 441,
|
||||
"ctxt": 0
|
||||
},
|
||||
"data": "\n ",
|
||||
"raw": "\n "
|
||||
},
|
||||
{
|
||||
"type": "Element",
|
||||
"span": {
|
||||
"start": 441,
|
||||
"end": 521,
|
||||
"ctxt": 0
|
||||
},
|
||||
"tagName": "foreignObject",
|
||||
"namespace": "http://www.w3.org/2000/svg",
|
||||
"attributes": [
|
||||
{
|
||||
"type": "Attribute",
|
||||
"span": {
|
||||
"start": 456,
|
||||
"end": 469,
|
||||
"ctxt": 0
|
||||
},
|
||||
"namespace": null,
|
||||
"prefix": null,
|
||||
"name": "width",
|
||||
"rawName": "width",
|
||||
"value": "100px",
|
||||
"rawValue": "\"100px\""
|
||||
},
|
||||
{
|
||||
"type": "Attribute",
|
||||
"span": {
|
||||
"start": 470,
|
||||
"end": 484,
|
||||
"ctxt": 0
|
||||
},
|
||||
"namespace": null,
|
||||
"prefix": null,
|
||||
"name": "height",
|
||||
"rawName": "height",
|
||||
"value": "100px",
|
||||
"rawValue": "\"100px\""
|
||||
}
|
||||
],
|
||||
"children": [
|
||||
{
|
||||
"type": "Comment",
|
||||
"span": {
|
||||
"start": 485,
|
||||
"end": 504,
|
||||
"ctxt": 0
|
||||
},
|
||||
"data": "[CDATA[content]]",
|
||||
"raw": "<![CDATA[content]]>"
|
||||
},
|
||||
{
|
||||
"type": "Text",
|
||||
"span": {
|
||||
"start": 504,
|
||||
"end": 505,
|
||||
"ctxt": 0
|
||||
},
|
||||
"data": "a",
|
||||
"raw": "a"
|
||||
}
|
||||
],
|
||||
"content": null,
|
||||
"isSelfClosing": false
|
||||
},
|
||||
{
|
||||
"type": "Text",
|
||||
"span": {
|
||||
"start": 521,
|
||||
"end": 526,
|
||||
"ctxt": 0
|
||||
},
|
||||
"data": "\n ",
|
||||
"raw": "\n "
|
||||
},
|
||||
{
|
||||
"type": "Element",
|
||||
"span": {
|
||||
"start": 526,
|
||||
"end": 558,
|
||||
"ctxt": 0
|
||||
},
|
||||
"tagName": "desc",
|
||||
"namespace": "http://www.w3.org/2000/svg",
|
||||
"attributes": [],
|
||||
"children": [
|
||||
{
|
||||
"type": "Comment",
|
||||
"span": {
|
||||
"start": 532,
|
||||
"end": 551,
|
||||
"ctxt": 0
|
||||
},
|
||||
"data": "[CDATA[content]]",
|
||||
"raw": "<![CDATA[content]]>"
|
||||
}
|
||||
],
|
||||
"content": null,
|
||||
"isSelfClosing": false
|
||||
},
|
||||
{
|
||||
"type": "Text",
|
||||
"span": {
|
||||
"start": 558,
|
||||
"end": 563,
|
||||
"ctxt": 0
|
||||
},
|
||||
"data": "\n ",
|
||||
"raw": "\n "
|
||||
},
|
||||
{
|
||||
"type": "Element",
|
||||
"span": {
|
||||
"start": 563,
|
||||
"end": 597,
|
||||
"ctxt": 0
|
||||
},
|
||||
"tagName": "title",
|
||||
"namespace": "http://www.w3.org/2000/svg",
|
||||
"attributes": [],
|
||||
"children": [
|
||||
{
|
||||
"type": "Comment",
|
||||
"span": {
|
||||
"start": 570,
|
||||
"end": 589,
|
||||
"ctxt": 0
|
||||
},
|
||||
"data": "[CDATA[content]]",
|
||||
"raw": "<![CDATA[content]]>"
|
||||
}
|
||||
],
|
||||
"content": null,
|
||||
"isSelfClosing": false
|
||||
},
|
||||
{
|
||||
"type": "Text",
|
||||
"span": {
|
||||
"start": 597,
|
||||
"end": 598,
|
||||
"ctxt": 0
|
||||
},
|
||||
"data": "\n",
|
||||
"raw": "\n"
|
||||
}
|
||||
],
|
||||
"content": null,
|
||||
"isSelfClosing": false
|
||||
},
|
||||
{
|
||||
"type": "Text",
|
||||
"span": {
|
||||
"start": 604,
|
||||
"end": 613,
|
||||
"ctxt": 0
|
||||
},
|
||||
"data": "\n\n",
|
||||
"raw": "\n\n"
|
||||
}
|
||||
],
|
||||
"content": null,
|
||||
"isSelfClosing": false
|
||||
}
|
||||
],
|
||||
"content": null,
|
||||
"isSelfClosing": false
|
||||
}
|
||||
]
|
||||
}
|
112
crates/swc_html_parser/tests/recovery/text/cdata/output.stderr
Normal file
112
crates/swc_html_parser/tests/recovery/text/cdata/output.stderr
Normal file
@ -0,0 +1,112 @@
|
||||
|
||||
x Cdata in html content
|
||||
,-[$DIR/tests/recovery/text/cdata/input.html:6:1]
|
||||
6 | <body>
|
||||
7 | <p><![CDATA[content]]></p>
|
||||
: ^
|
||||
8 | <p><![CDATA[&ing]]></p>
|
||||
`----
|
||||
|
||||
x Cdata in html content
|
||||
,-[$DIR/tests/recovery/text/cdata/input.html:7:1]
|
||||
7 | <p><![CDATA[content]]></p>
|
||||
8 | <p><![CDATA[&ing]]></p>
|
||||
: ^
|
||||
9 | <p><![CDATA[&ing ]]]></p>
|
||||
`----
|
||||
|
||||
x Cdata in html content
|
||||
,-[$DIR/tests/recovery/text/cdata/input.html:8:1]
|
||||
8 | <p><![CDATA[&ing]]></p>
|
||||
9 | <p><![CDATA[&ing ]]]></p>
|
||||
: ^
|
||||
10 | <p><![CDATA[&ing]] ]]></p>
|
||||
`----
|
||||
|
||||
x Cdata in html content
|
||||
,-[$DIR/tests/recovery/text/cdata/input.html:9:1]
|
||||
9 | <p><![CDATA[&ing ]]]></p>
|
||||
10 | <p><![CDATA[&ing]] ]]></p>
|
||||
: ^
|
||||
11 | <p><![CDATA[<message>text</message>]]></p>
|
||||
`----
|
||||
|
||||
x Cdata in html content
|
||||
,-[$DIR/tests/recovery/text/cdata/input.html:10:1]
|
||||
10 | <p><![CDATA[&ing]] ]]></p>
|
||||
11 | <p><![CDATA[<message>text</message>]]></p>
|
||||
: ^
|
||||
12 | <p><![CDATA[</this is malformed!</malformed</malformed & worse>]]></p>
|
||||
`----
|
||||
|
||||
x Stray end tag "message"
|
||||
,-[$DIR/tests/recovery/text/cdata/input.html:10:1]
|
||||
10 | <p><![CDATA[&ing]] ]]></p>
|
||||
11 | <p><![CDATA[<message>text</message>]]></p>
|
||||
: ^^^^^^^^^^
|
||||
12 | <p><![CDATA[</this is malformed!</malformed</malformed & worse>]]></p>
|
||||
`----
|
||||
|
||||
x Cdata in html content
|
||||
,-[$DIR/tests/recovery/text/cdata/input.html:11:1]
|
||||
11 | <p><![CDATA[<message>text</message>]]></p>
|
||||
12 | <p><![CDATA[</this is malformed!</malformed</malformed & worse>]]></p>
|
||||
: ^
|
||||
13 | <p><![CDATA[1]]><![CDATA[2]]></p>
|
||||
`----
|
||||
|
||||
x Cdata in html content
|
||||
,-[$DIR/tests/recovery/text/cdata/input.html:12:1]
|
||||
12 | <p><![CDATA[</this is malformed!</malformed</malformed & worse>]]></p>
|
||||
13 | <p><![CDATA[1]]><![CDATA[2]]></p>
|
||||
: ^
|
||||
14 | <p>
|
||||
`----
|
||||
|
||||
x Cdata in html content
|
||||
,-[$DIR/tests/recovery/text/cdata/input.html:12:1]
|
||||
12 | <p><![CDATA[</this is malformed!</malformed</malformed & worse>]]></p>
|
||||
13 | <p><![CDATA[1]]><![CDATA[2]]></p>
|
||||
: ^
|
||||
14 | <p>
|
||||
`----
|
||||
|
||||
x Cdata in html content
|
||||
,-[$DIR/tests/recovery/text/cdata/input.html:14:1]
|
||||
14 | <p>
|
||||
15 | <![CDATA[data]]>
|
||||
: ^
|
||||
16 | </p>
|
||||
`----
|
||||
|
||||
x Cdata in html content
|
||||
,-[$DIR/tests/recovery/text/cdata/input.html:16:1]
|
||||
16 | </p>
|
||||
17 | <p><![CDATA[bracket ]after]]></p>
|
||||
: ^
|
||||
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>
|
||||
`----
|
1048
crates/swc_html_parser/tests/recovery/text/cdata/span.rust-debug
Normal file
1048
crates/swc_html_parser/tests/recovery/text/cdata/span.rust-debug
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user