fix(html/parser): Fix parsing of comments in textarea (#4530)

This commit is contained in:
Alexander Akait 2022-05-05 06:13:20 +03:00 committed by GitHub
parent f87d94a50e
commit 79090e1b2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 234 additions and 8 deletions

View File

@ -3,5 +3,5 @@
</head>
<body>
<textarea name=test id=test></textarea>
&lt;/body&gt;
&lt;/html&gt;</body></html>
</body></html>

View File

@ -3398,14 +3398,16 @@ where
Token::StartTag { tag_name, .. } if tag_name == "textarea" => {
self.insert_html_element(token_and_info)?;
// To prevent parsing more tokens in lexer we set state before taking
self.input.set_input_state(State::Rcdata);
match self.input.cur()? {
Some(Token::Character { value, .. }) if *value == '\x0A' => {
bump!(self);
}
_ => {}
}
};
self.input.set_input_state(State::Rcdata);
self.original_insertion_mode = self.insertion_mode.clone();
self.frameset_ok = false;
self.insertion_mode = InsertionMode::Text;

View File

@ -0,0 +1 @@
<textarea><!--</textarea>--></textarea>

View File

@ -0,0 +1,84 @@
{
"type": "Document",
"span": {
"start": 0,
"end": 39,
"ctxt": 0
},
"mode": "no-quirks",
"children": [
{
"type": "Element",
"span": {
"start": 0,
"end": 28,
"ctxt": 0
},
"tagName": "html",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [
{
"type": "Element",
"span": {
"start": 0,
"end": 10,
"ctxt": 0
},
"tagName": "head",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [],
"content": null
},
{
"type": "Element",
"span": {
"start": 0,
"end": 28,
"ctxt": 0
},
"tagName": "body",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [
{
"type": "Element",
"span": {
"start": 0,
"end": 14,
"ctxt": 0
},
"tagName": "textarea",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [
{
"type": "Text",
"span": {
"start": 10,
"end": 14,
"ctxt": 0
},
"value": "<!--"
}
],
"content": null
},
{
"type": "Text",
"span": {
"start": 25,
"end": 28,
"ctxt": 0
},
"value": "-->"
}
],
"content": null
}
],
"content": null
}
]
}

View File

@ -0,0 +1,6 @@
x Unexpected token
,-[$DIR/tests/recovery/comment/inside-textarea/input.html:1:1]
1 | <textarea><!--</textarea>--></textarea>
: ^^^^^^^^^^^
`----

View File

@ -0,0 +1,66 @@
x Document
,-[$DIR/tests/recovery/comment/inside-textarea/input.html:1:1]
1 | <textarea><!--</textarea>--></textarea>
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----
x Child
,-[$DIR/tests/recovery/comment/inside-textarea/input.html:1:1]
1 | <textarea><!--</textarea>--></textarea>
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----
x Element
,-[$DIR/tests/recovery/comment/inside-textarea/input.html:1:1]
1 | <textarea><!--</textarea>--></textarea>
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----
x Child
,-[$DIR/tests/recovery/comment/inside-textarea/input.html:1:1]
1 | <textarea><!--</textarea>--></textarea>
: ^^^^^^^^^^
`----
x Element
,-[$DIR/tests/recovery/comment/inside-textarea/input.html:1:1]
1 | <textarea><!--</textarea>--></textarea>
: ^^^^^^^^^^
`----
x Child
,-[$DIR/tests/recovery/comment/inside-textarea/input.html:1:1]
1 | <textarea><!--</textarea>--></textarea>
: ^^^^^^^^^^^^^^
`----
x Element
,-[$DIR/tests/recovery/comment/inside-textarea/input.html:1:1]
1 | <textarea><!--</textarea>--></textarea>
: ^^^^^^^^^^^^^^
`----
x Child
,-[$DIR/tests/recovery/comment/inside-textarea/input.html:1:1]
1 | <textarea><!--</textarea>--></textarea>
: ^^^^
`----
x Text
,-[$DIR/tests/recovery/comment/inside-textarea/input.html:1:1]
1 | <textarea><!--</textarea>--></textarea>
: ^^^^
`----
x Child
,-[$DIR/tests/recovery/comment/inside-textarea/input.html:1:1]
1 | <textarea><!--</textarea>--></textarea>
: ^^^
`----
x Text
,-[$DIR/tests/recovery/comment/inside-textarea/input.html:1:1]
1 | <textarea><!--</textarea>--></textarea>
: ^^^
`----

View File

@ -11,7 +11,7 @@
"type": "Element",
"span": {
"start": 0,
"end": 10,
"end": 28,
"ctxt": 0
},
"tagName": "html",
@ -35,7 +35,7 @@
"type": "Element",
"span": {
"start": 0,
"end": 10,
"end": 28,
"ctxt": 0
},
"tagName": "body",
@ -46,14 +46,33 @@
"type": "Element",
"span": {
"start": 0,
"end": 10,
"end": 14,
"ctxt": 0
},
"tagName": "textarea",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [],
"children": [
{
"type": "Text",
"span": {
"start": 10,
"end": 14,
"ctxt": 0
},
"value": "<!--"
}
],
"content": null
},
{
"type": "Text",
"span": {
"start": 25,
"end": 28,
"ctxt": 0
},
"value": "-->"
}
],
"content": null

View File

@ -5,6 +5,18 @@
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----
x Child
,-[$DIR/tests/recovery/element/textarea/input.html:1:1]
1 | <textarea><!--</textarea>--></textarea>
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----
x Element
,-[$DIR/tests/recovery/element/textarea/input.html:1:1]
1 | <textarea><!--</textarea>--></textarea>
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----
x Child
,-[$DIR/tests/recovery/element/textarea/input.html:1:1]
1 | <textarea><!--</textarea>--></textarea>
@ -16,3 +28,39 @@
1 | <textarea><!--</textarea>--></textarea>
: ^^^^^^^^^^
`----
x Child
,-[$DIR/tests/recovery/element/textarea/input.html:1:1]
1 | <textarea><!--</textarea>--></textarea>
: ^^^^^^^^^^^^^^
`----
x Element
,-[$DIR/tests/recovery/element/textarea/input.html:1:1]
1 | <textarea><!--</textarea>--></textarea>
: ^^^^^^^^^^^^^^
`----
x Child
,-[$DIR/tests/recovery/element/textarea/input.html:1:1]
1 | <textarea><!--</textarea>--></textarea>
: ^^^^
`----
x Text
,-[$DIR/tests/recovery/element/textarea/input.html:1:1]
1 | <textarea><!--</textarea>--></textarea>
: ^^^^
`----
x Child
,-[$DIR/tests/recovery/element/textarea/input.html:1:1]
1 | <textarea><!--</textarea>--></textarea>
: ^^^
`----
x Text
,-[$DIR/tests/recovery/element/textarea/input.html:1:1]
1 | <textarea><!--</textarea>--></textarea>
: ^^^
`----