Make WordPress Core


Ignore:
Timestamp:
04/24/2024 07:43:02 AM (19 months ago)
Author:
dmsnell
Message:

HTML API: Fix detection of single-length funky comments.

Since [60428] the Tag Processor has been misidentifying single-character
funky comments. It has been asserting that the full token-length for a
funky comment must be at least three characters after the opening (e.g.
</1>), but it has been starting to look for the closing > after
those same three characters. This means that it has been skipping the
actual close of these funky comments and swallowing up the next syntax
until it finds a >, often consuming the next tag in the process.

This patch fixes the detector and restores finding the following token.

Developed in https://github.com/WordPress/wordpress-develop/pull/6412
Discussed in https://core.trac.wordpress.org/ticket/60170

Follow-up to [60428].
Fixes #60170.
Props dmsnell, gziolo, jonsurrell.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/html-api/class-wp-html-tag-processor.php

    r57987 r58040  
    16301630             * https://html.spec.whatwg.org/multipage/parsing.html#markup-declaration-open-state
    16311631             */
    1632             if ( '!' === $html[ $at + 1 ] ) {
     1632            if ( ! $this->is_closing_tag && '!' === $html[ $at + 1 ] ) {
    16331633                /*
    16341634                 * `<!--` transitions to a comment state – apply further comment rules.
     
    18101810             */
    18111811            if ( '>' === $html[ $at + 1 ] ) {
     1812                // `<>` is interpreted as plaintext.
     1813                if ( ! $this->is_closing_tag ) {
     1814                    ++$at;
     1815                    continue;
     1816                }
     1817
    18121818                $this->parser_state         = self::STATE_PRESUMPTUOUS_TAG;
    18131819                $this->token_length         = $at + 2 - $this->token_starts_at;
     
    18201826             * See https://html.spec.whatwg.org/multipage/parsing.html#tag-open-state
    18211827             */
    1822             if ( '?' === $html[ $at + 1 ] ) {
     1828            if ( ! $this->is_closing_tag && '?' === $html[ $at + 1 ] ) {
    18231829                $closer_at = strpos( $html, '>', $at + 2 );
    18241830                if ( false === $closer_at ) {
     
    18921898                }
    18931899
    1894                 $closer_at = strpos( $html, '>', $at + 3 );
     1900                $closer_at = strpos( $html, '>', $at + 2 );
    18951901                if ( false === $closer_at ) {
    18961902                    $this->parser_state = self::STATE_INCOMPLETE_INPUT;
Note: See TracChangeset for help on using the changeset viewer.