-
Notifications
You must be signed in to change notification settings - Fork 115
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Continue parsing as data after invalid opening tag #253
base: master
Are you sure you want to change the base?
Conversation
Per the spec: > Parse error. Switch to the data state. Emit a U+003C LESS-THAN SIGN character token. Reconsume the current input character. https://www.w3.org/TR/2014/REC-html5-20141028/syntax.html#tag-open-state fixes Masterminds#250
up please 🙏 |
I think it's 13.2.5.6 Tag open state, isn't it?
The consequences are the same (adding |
@@ -526,7 +526,7 @@ public function testTagNotClosedAfterTagName() | |||
$this->assertEventError($events->get(0)); | |||
$this->assertEventEquals('startTag', 'span', $events->get(1)); | |||
$this->assertEventError($events->get(2)); | |||
$this->assertEventEquals('text', '>02', $events->get(3)); | |||
$this->assertEventEquals('text', '<>02', $events->get(3)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, the parser would be in the 13.2.5.8 Tag name state - thus, form my POV the startTag should be span<
and the text just 02
.
\Masterminds\HTML5\Parser\Tokenizer::consumeData
checks for is_alpha($tok)
and thus skips <
for the tag name. It seems the states are "optimized" in the current implementation.
In general I think that the current state of the test is still fine (having <>02
as text
).
There might be a comment above the test that there is this divergence to the specs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the parser should be in tag name state, but tag name parsing does not quite follow the spec. It only consumes a restricted set of characters and then enters attribute state, where the spec indicates that the character should be part of the tag name. Attribute state parsing also does not quite follow the spec in that it exits as soon as it encounters the <
, where the spec indicates it should be treated as part of an attribute name while in that state (thus <span <>02</span>
also does not produce the correct output). At this point the parser re-enters the data state and the character combo <>
does not match a known state and so is consumed as data. With the change to the data state handling the extra <
is exposed whereas before it was just swallowed.
That was the meaning behind my comment in 250 that there are other issues to address. It took me a while to get the data state parsing right, so I didn't want to immediately dive into the parsing issues with the other states.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original issue is referencing problems in the data state and that was what I was attempting to address. Instead of a comment here, the parsing issues in tag name and attribute name could be addressed now in this PR or a new issue outlining the problem in those states could be opened with information about the divergence. I was primarily waiting to see what feedback I got on the current change before deciding whether to address those issues here or open a new issue and defer the additional work.
I was attempting to address issues consuming the |
Per section 8.2.4.1 of spec version 20141028:
Note: the 20141028 version of the spec was used because the section numbering matches up with existing references in code. The relevant section for the living HTML5 spec is 13.2.5.1 and provides similar guidance.
fixes #250