HTML API: Fix invalid comment syntax cases#4256
HTML API: Fix invalid comment syntax cases#4256dmsnell wants to merge 14 commits intoWordPress:trunkfrom
Conversation
f841c78 to
25df194
Compare
This is just a safety precaution to mitigate an accidental removal of the pointer increment. No actual problems motivated this change.
f6cfa42 to
2f22fda
Compare
| /* | ||
| * Abruptly-closed empty comments are a sequence of dashes followed by `>`. | ||
| */ |
There was a problem hiding this comment.
| /* | |
| * Abruptly-closed empty comments are a sequence of dashes followed by `>`. | |
| */ | |
| // Abruptly-closed empty comments are a sequence of dashes followed by `>`. |
This should use the single line comment format.
| * @ticket 58007 | ||
| * @dataProvider data_next_tag_ignores_invalid_first_character_of_tag_name_comments |
There was a problem hiding this comment.
| * @ticket 58007 | |
| * @dataProvider data_next_tag_ignores_invalid_first_character_of_tag_name_comments | |
| * @ticket 58007 | |
| * | |
| * @dataProvider data_next_tag_ignores_invalid_first_character_of_tag_name_comments |
@ticket and @dataProvider should be separated by an empty line
| * @ticket 58007 | ||
| * @dataProvider data_next_tag_ignores_invalid_first_character_of_tag_name_comments | ||
| * | ||
| * @param string $html_with_markers HTML containing an invalid tag closer whose element before and element after contain the "start" and "end" CSS classes. |
There was a problem hiding this comment.
| * @param string $html_with_markers HTML containing an invalid tag closer whose element before and element after contain the "start" and "end" CSS classes. | |
| * @param string $html_with_markers HTML containing an invalid tag closer whose element before | |
| and element after contain the "start" and "end" CSS classes. |
Let's break this line to limit the need for horizontal scrolling.
| * | ||
| * @ticket 58007 |
There was a problem hiding this comment.
| * | |
| * @ticket 58007 |
Data providers don't need the @ticket annotation
| return false; | ||
| } | ||
|
|
||
| if ( '>' === $html[ $closer_at + 2 ] ) { |
There was a problem hiding this comment.
Is it possible that $closer_at + 2 may not exist as an offset?
Props to @costdev for noting the unchecked indices.
| * | ||
| * @dataProvider data_next_tag_ignores_invalid_first_character_of_tag_name_comments |
There was a problem hiding this comment.
| * | |
| * @dataProvider data_next_tag_ignores_invalid_first_character_of_tag_name_comments | |
| * | |
| * @covers WP_HTML_Tag_Processor::next_tag | |
| * | |
| * @dataProvider data_next_tag_ignores_invalid_first_character_of_tag_name_comments |
See this ticket as a reference for the test docblock order/spacing of annotations.
| * @ticket 58007 | ||
| * @covers WP_HTML_Tag_Processor::next_tag |
There was a problem hiding this comment.
| * @ticket 58007 | |
| * @covers WP_HTML_Tag_Processor::next_tag | |
| * @ticket 58007 | |
| * | |
| * @covers WP_HTML_Tag_Processor::next_tag |
| * @covers WP_HTML_Tag_Processor::next_tag | ||
| * @dataProvider data_html_with_unclosed_comments |
There was a problem hiding this comment.
| * @covers WP_HTML_Tag_Processor::next_tag | |
| * @dataProvider data_html_with_unclosed_comments | |
| * @covers WP_HTML_Tag_Processor::next_tag | |
| * | |
| * @dataProvider data_html_with_unclosed_comments |
| * @covers WP_HTML_Tag_Processor::next_tag | ||
| * @dataProvider data_abruptly_closed_empty_comments |
There was a problem hiding this comment.
| * @covers WP_HTML_Tag_Processor::next_tag | |
| * @dataProvider data_abruptly_closed_empty_comments | |
| * @covers WP_HTML_Tag_Processor::next_tag | |
| * | |
| * @dataProvider data_abruptly_closed_empty_comments |
|
@costdev I think I've addressed all your comments now, thanks. must say I tried to get the docblock ordering and formatting right, but for some reason that's consistently hard to do |
|
So there were @costdev - sorry for missing that. I'll double-check once the tests finish again to make sure no remain. |
| * If a non-alpha starts the tag name in a tag closer it's a comment. | ||
| * Find the first `>`, which closes the comment. | ||
| * | ||
| * See https://github.com/WordPress/wordpress-develop/pull/4256 |
There was a problem hiding this comment.
Would it make sense to link to the spec as a somewhat more canonical source instead? While it's fair that this PR states the intent behind this change, I've been itching to see why we can actually do this 😅
How about e.g.
| * See https://github.com/WordPress/wordpress-develop/pull/4256 | |
| * See https://html.spec.whatwg.org/#parse-error-invalid-first-character-of-tag-name |
(which is the reference we're also using in the tests)
There was a problem hiding this comment.
good catch; this was probably me pasting the wrong thing and not noticing it
663055b to
47d4b4f
Compare
|
Committed to Core |
|
Backported to Core's |
- Support a few extra invalid comment syntaxes. WordPress/wordpress-develop#4256 - Invalidate bookmarks which have been eliminated by enqueued changes. WordPress/wordpress-develop#4116 - Expose whether the currently-matched tag has the self-closing flag. WordPress/wordpress-develop#4266 - Avoid double-writing an attribute value if given case-variations of the name. WordPress/wordpress-develop#4337
- Support a few extra invalid comment syntaxes. WordPress/wordpress-develop#4256 - Invalidate bookmarks which have been eliminated by enqueued changes. WordPress/wordpress-develop#4116 - Expose whether the currently-matched tag has the self-closing flag. WordPress/wordpress-develop#4266 - Avoid double-writing an attribute value if given case-variations of the name. WordPress/wordpress-develop#4337 - Linting updates from WordPress/wordpress-develop#4360.
- Support a few extra invalid comment syntaxes. WordPress/wordpress-develop#4256 - Invalidate bookmarks which have been eliminated by enqueued changes. WordPress/wordpress-develop#4116 - Expose whether the currently-matched tag has the self-closing flag. WordPress/wordpress-develop#4266 - Avoid double-writing an attribute value if given case-variations of the name. WordPress/wordpress-develop#4337 - Linting updates from WordPress/wordpress-develop#4360. - Avoid losing previous updates in certain cases when seeking earlier in a document. WordPress/wordpress-develop#4345
Status
What
Adds support for a few invalid HTML comment forms.
</3>--!>closer (comments should be closed by-->but if the!appears it will also close it, in error).</>Why
We want to continue to find and handle edge cases in HTML so that the Tag Processor remains reliable in the face of unexpected inputs.
How
Captures the patterns described in the HTML specification for parse errors relating to invalid comment construction. Since these are comments it's appropriate to proceed consuming input until the end, and there's no need to look for other tags or attributes in the process.
cc: @adamziel @gziolo