Skip to content
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

HTML API: Join text nodes on invalid-tag-name boundaries. #6041

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/wp-includes/html-api/class-wp-html-tag-processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -1528,20 +1528,26 @@ private function parse_next_tag() {

if ( $at > $was_at ) {
/*
* A "<" has been found in the document. That may be the start of another node, or
* it may be an "ivalid-first-character-of-tag-name" error. If this is not the start
* of another node the "<" should be included in this text node and another
* termination point should be found for the text node.
* A "<" normally starts a new HTML tag or syntax token, but in cases where the
* following character can't produce a valid token, the "<" is instead treated
* as plaintext and the parser should skip over it. This avoids a problem when
* following earlier practices of typing emoji with text, e.g. "<3". This
* should be a heart, not a tag. It's supposed to be rendered, not hidden.
*
* At this point the parser checks if this is one of those cases and if it is
* will continue searching for the next "<" in search of a token boundary.
*
* @see https://html.spec.whatwg.org/#tag-open-state
*/
if ( strlen( $html ) > $at + 1 ) {
$next_character = $html[ $at + 1 ];
$at_another_node =
$at_another_node = (
'!' === $next_character ||
'/' === $next_character ||
'?' === $next_character ||
( 'A' <= $next_character && $next_character <= 'z' );
( 'A' <= $next_character && $next_character <= 'Z' ) ||
( 'a' <= $next_character && $next_character <= 'z' )
);
if ( ! $at_another_node ) {
++$at;
continue;
Expand Down
Loading