fix(html/parser): Fix parsing of nobr (#4535)

This commit is contained in:
Alexander Akait 2022-05-06 07:34:06 +03:00 committed by GitHub
parent e4ce388632
commit e6042a5e69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 724 additions and 56 deletions

View File

@ -3075,15 +3075,15 @@ where
self.run_the_adoption_agency_algorithm(token_and_info)?;
self.reconstruct_active_formatting_elements()?;
} else {
let element = self.insert_html_element(&mut token_and_info.clone())?;
self.active_formatting_elements
.push(ActiveFormattingElement::Element(
element,
token_and_info.clone(),
));
}
let element = self.insert_html_element(&mut token_and_info.clone())?;
self.active_formatting_elements
.push(ActiveFormattingElement::Element(
element,
token_and_info.clone(),
));
}
// An end tag whose tag name is one of: "a", "b", "big", "code", "em", "font",
// "i", "nobr", "s", "small", "strike", "strong", "tt", "u"

View File

@ -22,7 +22,7 @@
"type": "Element",
"span": {
"start": 0,
"end": 109,
"end": 115,
"ctxt": 0
},
"tagName": "html",
@ -46,7 +46,7 @@
"type": "Element",
"span": {
"start": 15,
"end": 109,
"end": 115,
"ctxt": 0
},
"tagName": "body",
@ -57,7 +57,7 @@
"type": "Element",
"span": {
"start": 21,
"end": 41,
"end": 47,
"ctxt": 0
},
"tagName": "a",
@ -99,6 +99,19 @@
}
],
"content": null
},
{
"type": "Element",
"span": {
"start": 41,
"end": 47,
"ctxt": 0
},
"tagName": "nobr",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [],
"content": null
}
],
"content": null
@ -106,21 +119,61 @@
{
"type": "Element",
"span": {
"start": 51,
"end": 55,
"start": 41,
"end": 68,
"ctxt": 0
},
"tagName": "br",
"tagName": "nobr",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [],
"children": [
{
"type": "Element",
"span": {
"start": 51,
"end": 55,
"ctxt": 0
},
"tagName": "br",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [],
"content": null
},
{
"type": "Element",
"span": {
"start": 55,
"end": 68,
"ctxt": 0
},
"tagName": "a",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [
{
"type": "Attribute",
"span": {
"start": 0,
"end": 0,
"ctxt": 0
},
"namespace": null,
"prefix": null,
"name": "href",
"value": "#2"
}
],
"children": [],
"content": null
}
],
"content": null
},
{
"type": "Element",
"span": {
"start": 55,
"end": 75,
"end": 81,
"ctxt": 0
},
"tagName": "a",
@ -162,6 +215,19 @@
}
],
"content": null
},
{
"type": "Element",
"span": {
"start": 75,
"end": 81,
"ctxt": 0
},
"tagName": "nobr",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [],
"content": null
}
],
"content": null
@ -169,21 +235,61 @@
{
"type": "Element",
"span": {
"start": 85,
"end": 89,
"start": 75,
"end": 102,
"ctxt": 0
},
"tagName": "br",
"tagName": "nobr",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [],
"children": [
{
"type": "Element",
"span": {
"start": 85,
"end": 89,
"ctxt": 0
},
"tagName": "br",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [],
"content": null
},
{
"type": "Element",
"span": {
"start": 89,
"end": 102,
"ctxt": 0
},
"tagName": "a",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [
{
"type": "Attribute",
"span": {
"start": 0,
"end": 0,
"ctxt": 0
},
"namespace": null,
"prefix": null,
"name": "href",
"value": "#3"
}
],
"children": [],
"content": null
}
],
"content": null
},
{
"type": "Element",
"span": {
"start": 89,
"end": 109,
"end": 115,
"ctxt": 0
},
"tagName": "a",
@ -225,6 +331,19 @@
}
],
"content": null
},
{
"type": "Element",
"span": {
"start": 109,
"end": 115,
"ctxt": 0
},
"tagName": "nobr",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [],
"content": null
}
],
"content": null

View File

@ -57,7 +57,7 @@
"type": "Element",
"span": {
"start": 21,
"end": 31,
"end": 37,
"ctxt": 0
},
"tagName": "b",
@ -86,6 +86,46 @@
}
],
"content": null
},
{
"type": "Element",
"span": {
"start": 31,
"end": 37,
"ctxt": 0
},
"tagName": "nobr",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [],
"content": null
}
],
"content": null
},
{
"type": "Element",
"span": {
"start": 31,
"end": 44,
"ctxt": 0
},
"tagName": "nobr",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [
{
"type": "Element",
"span": {
"start": 41,
"end": 44,
"ctxt": 0
},
"tagName": "i",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [],
"content": null
}
],
"content": null
@ -94,7 +134,7 @@
"type": "Element",
"span": {
"start": 41,
"end": 51,
"end": 57,
"ctxt": 0
},
"tagName": "i",
@ -123,18 +163,45 @@
}
],
"content": null
},
{
"type": "Element",
"span": {
"start": 51,
"end": 57,
"ctxt": 0
},
"tagName": "nobr",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [],
"content": null
}
],
"content": null
},
{
"type": "Text",
"type": "Element",
"span": {
"start": 61,
"start": 51,
"end": 62,
"ctxt": 0
},
"value": "3"
"tagName": "nobr",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [
{
"type": "Text",
"span": {
"start": 61,
"end": 62,
"ctxt": 0
},
"value": "3"
}
],
"content": null
}
],
"content": null

View File

@ -123,13 +123,27 @@
"attributes": [],
"children": [
{
"type": "Text",
"type": "Element",
"span": {
"start": 57,
"start": 51,
"end": 58,
"ctxt": 0
},
"value": "2"
"tagName": "nobr",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [
{
"type": "Text",
"span": {
"start": 57,
"end": 58,
"ctxt": 0
},
"value": "2"
}
],
"content": null
},
{
"type": "Element",

View File

@ -167,13 +167,27 @@
"attributes": [],
"children": [
{
"type": "Text",
"type": "Element",
"span": {
"start": 65,
"start": 59,
"end": 66,
"ctxt": 0
},
"value": "2"
"tagName": "nobr",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [
{
"type": "Text",
"span": {
"start": 65,
"end": 66,
"ctxt": 0
},
"value": "2"
}
],
"content": null
},
{
"type": "Element",

View File

@ -124,6 +124,46 @@
"attributes": [],
"children": [],
"content": null
},
{
"type": "Element",
"span": {
"start": 36,
"end": 42,
"ctxt": 0
},
"tagName": "nobr",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [],
"content": null
}
],
"content": null
},
{
"type": "Element",
"span": {
"start": 36,
"end": 49,
"ctxt": 0
},
"tagName": "nobr",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [
{
"type": "Element",
"span": {
"start": 46,
"end": 49,
"ctxt": 0
},
"tagName": "i",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [],
"content": null
}
],
"content": null
@ -132,7 +172,7 @@
"type": "Element",
"span": {
"start": 46,
"end": 56,
"end": 62,
"ctxt": 0
},
"tagName": "i",
@ -161,18 +201,45 @@
}
],
"content": null
},
{
"type": "Element",
"span": {
"start": 56,
"end": 62,
"ctxt": 0
},
"tagName": "nobr",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [],
"content": null
}
],
"content": null
},
{
"type": "Text",
"type": "Element",
"span": {
"start": 66,
"start": 56,
"end": 67,
"ctxt": 0
},
"value": "3"
"tagName": "nobr",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [
{
"type": "Text",
"span": {
"start": 66,
"end": 67,
"ctxt": 0
},
"value": "3"
}
],
"content": null
}
],
"content": null

View File

@ -57,7 +57,7 @@
"type": "Element",
"span": {
"start": 21,
"end": 31,
"end": 37,
"ctxt": 0
},
"tagName": "b",
@ -86,6 +86,19 @@
}
],
"content": null
},
{
"type": "Element",
"span": {
"start": 31,
"end": 37,
"ctxt": 0
},
"tagName": "nobr",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [],
"content": null
}
],
"content": null
@ -101,11 +114,38 @@
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [
{
"type": "Element",
"span": {
"start": 31,
"end": 49,
"ctxt": 0
},
"tagName": "nobr",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [
{
"type": "Element",
"span": {
"start": 46,
"end": 49,
"ctxt": 0
},
"tagName": "i",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [],
"content": null
}
],
"content": null
},
{
"type": "Element",
"span": {
"start": 46,
"end": 56,
"end": 62,
"ctxt": 0
},
"tagName": "i",
@ -134,18 +174,45 @@
}
],
"content": null
},
{
"type": "Element",
"span": {
"start": 56,
"end": 62,
"ctxt": 0
},
"tagName": "nobr",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [],
"content": null
}
],
"content": null
},
{
"type": "Text",
"type": "Element",
"span": {
"start": 66,
"start": 56,
"end": 67,
"ctxt": 0
},
"value": "3"
"tagName": "nobr",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [
{
"type": "Text",
"span": {
"start": 66,
"end": 67,
"ctxt": 0
},
"value": "3"
}
],
"content": null
}
],
"content": null

View File

@ -90,11 +90,52 @@
{
"type": "Element",
"span": {
"start": 37,
"start": 31,
"end": 42,
"ctxt": 0
},
"tagName": "ins",
"tagName": "nobr",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [
{
"type": "Element",
"span": {
"start": 37,
"end": 42,
"ctxt": 0
},
"tagName": "ins",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [],
"content": null
}
],
"content": null
}
],
"content": null
},
{
"type": "Element",
"span": {
"start": 31,
"end": 49,
"ctxt": 0
},
"tagName": "nobr",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [
{
"type": "Element",
"span": {
"start": 46,
"end": 49,
"ctxt": 0
},
"tagName": "i",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [],

View File

@ -57,7 +57,7 @@
"type": "Element",
"span": {
"start": 21,
"end": 36,
"end": 42,
"ctxt": 0
},
"tagName": "b",
@ -99,6 +99,19 @@
}
],
"content": null
},
{
"type": "Element",
"span": {
"start": 36,
"end": 42,
"ctxt": 0
},
"tagName": "nobr",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [],
"content": null
}
],
"content": null
@ -106,22 +119,36 @@
{
"type": "Element",
"span": {
"start": 46,
"start": 36,
"end": 50,
"ctxt": 0
},
"tagName": "i",
"tagName": "nobr",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [
{
"type": "Text",
"type": "Element",
"span": {
"start": 49,
"start": 46,
"end": 50,
"ctxt": 0
},
"value": "2"
"tagName": "i",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [
{
"type": "Text",
"span": {
"start": 49,
"end": 50,
"ctxt": 0
},
"value": "2"
}
],
"content": null
}
],
"content": null

View File

@ -128,13 +128,27 @@
"attributes": [],
"children": [
{
"type": "Text",
"type": "Element",
"span": {
"start": 44,
"start": 38,
"end": 45,
"ctxt": 0
},
"value": "2"
"tagName": "nobr",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [
{
"type": "Text",
"span": {
"start": 44,
"end": 45,
"ctxt": 0
},
"value": "2"
}
],
"content": null
}
],
"content": null

View File

@ -66,6 +66,19 @@
"children": [],
"content": null
},
{
"type": "Element",
"span": {
"start": 21,
"end": 27,
"ctxt": 0
},
"tagName": "nobr",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [],
"content": null
},
{
"type": "Element",
"span": {

View File

@ -66,6 +66,19 @@
"children": [],
"content": null
},
{
"type": "Element",
"span": {
"start": 21,
"end": 27,
"ctxt": 0
},
"tagName": "nobr",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [],
"content": null
},
{
"type": "Element",
"span": {

View File

@ -11,7 +11,7 @@
"type": "Element",
"span": {
"start": 0,
"end": 26,
"end": 32,
"ctxt": 0
},
"tagName": "html",
@ -35,7 +35,7 @@
"type": "Element",
"span": {
"start": 0,
"end": 26,
"end": 32,
"ctxt": 0
},
"tagName": "body",
@ -73,7 +73,7 @@
"type": "Element",
"span": {
"start": 14,
"end": 26,
"end": 32,
"ctxt": 0
},
"tagName": "div",
@ -84,7 +84,7 @@
"type": "Element",
"span": {
"start": 5,
"end": 26,
"end": 32,
"ctxt": 0
},
"tagName": "b",
@ -113,6 +113,19 @@
}
],
"content": null
},
{
"type": "Element",
"span": {
"start": 26,
"end": 32,
"ctxt": 0
},
"tagName": "nobr",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [],
"content": null
}
],
"content": null

View File

@ -0,0 +1 @@
<!doctype html><nobr><nobr><nobr>

View File

@ -0,0 +1,102 @@
{
"type": "Document",
"span": {
"start": 0,
"end": 33,
"ctxt": 0
},
"mode": "no-quirks",
"children": [
{
"type": "DocumentType",
"span": {
"start": 0,
"end": 15,
"ctxt": 0
},
"name": "html",
"publicId": null,
"systemId": null
},
{
"type": "Element",
"span": {
"start": 0,
"end": 33,
"ctxt": 0
},
"tagName": "html",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [
{
"type": "Element",
"span": {
"start": 0,
"end": 21,
"ctxt": 0
},
"tagName": "head",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [],
"content": null
},
{
"type": "Element",
"span": {
"start": 0,
"end": 33,
"ctxt": 0
},
"tagName": "body",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [
{
"type": "Element",
"span": {
"start": 15,
"end": 21,
"ctxt": 0
},
"tagName": "nobr",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [],
"content": null
},
{
"type": "Element",
"span": {
"start": 21,
"end": 27,
"ctxt": 0
},
"tagName": "nobr",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [],
"content": null
},
{
"type": "Element",
"span": {
"start": 27,
"end": 33,
"ctxt": 0
},
"tagName": "nobr",
"namespace": "http://www.w3.org/1999/xhtml",
"attributes": [],
"children": [],
"content": null
}
],
"content": null
}
],
"content": null
}
]
}

View File

@ -0,0 +1,18 @@
x Unexpected token
,-[$DIR/tests/recovery/element/nobr-1/input.html:1:1]
1 | <!doctype html><nobr><nobr><nobr>
: ^^^^^^
`----
x Unexpected token
,-[$DIR/tests/recovery/element/nobr-1/input.html:1:1]
1 | <!doctype html><nobr><nobr><nobr>
: ^^^^^^
`----
x Unexpected token
,-[$DIR/tests/recovery/element/nobr-1/input.html:1:1]
1 | <!doctype html><nobr><nobr><nobr>
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----

View File

@ -0,0 +1,78 @@
x Document
,-[$DIR/tests/recovery/element/nobr-1/input.html:1:1]
1 | <!doctype html><nobr><nobr><nobr>
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----
x Child
,-[$DIR/tests/recovery/element/nobr-1/input.html:1:1]
1 | <!doctype html><nobr><nobr><nobr>
: ^^^^^^^^^^^^^^^
`----
x DocumentType
,-[$DIR/tests/recovery/element/nobr-1/input.html:1:1]
1 | <!doctype html><nobr><nobr><nobr>
: ^^^^^^^^^^^^^^^
`----
x Child
,-[$DIR/tests/recovery/element/nobr-1/input.html:1:1]
1 | <!doctype html><nobr><nobr><nobr>
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----
x Element
,-[$DIR/tests/recovery/element/nobr-1/input.html:1:1]
1 | <!doctype html><nobr><nobr><nobr>
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----
x Child
,-[$DIR/tests/recovery/element/nobr-1/input.html:1:1]
1 | <!doctype html><nobr><nobr><nobr>
: ^^^^^^^^^^^^^^^^^^^^^
`----
x Element
,-[$DIR/tests/recovery/element/nobr-1/input.html:1:1]
1 | <!doctype html><nobr><nobr><nobr>
: ^^^^^^^^^^^^^^^^^^^^^
`----
x Child
,-[$DIR/tests/recovery/element/nobr-1/input.html:1:1]
1 | <!doctype html><nobr><nobr><nobr>
: ^^^^^^
`----
x Element
,-[$DIR/tests/recovery/element/nobr-1/input.html:1:1]
1 | <!doctype html><nobr><nobr><nobr>
: ^^^^^^
`----
x Child
,-[$DIR/tests/recovery/element/nobr-1/input.html:1:1]
1 | <!doctype html><nobr><nobr><nobr>
: ^^^^^^
`----
x Element
,-[$DIR/tests/recovery/element/nobr-1/input.html:1:1]
1 | <!doctype html><nobr><nobr><nobr>
: ^^^^^^
`----
x Child
,-[$DIR/tests/recovery/element/nobr-1/input.html:1:1]
1 | <!doctype html><nobr><nobr><nobr>
: ^^^^^^
`----
x Element
,-[$DIR/tests/recovery/element/nobr-1/input.html:1:1]
1 | <!doctype html><nobr><nobr><nobr>
: ^^^^^^
`----