Make WordPress Core


Ignore:
Timestamp:
01/30/2024 10:07:42 PM (5 months ago)
Author:
dmsnell
Message:

HTML API: Fix splitting single text node.

When next_token() was introduced, it brought a subtle bug. When encountering a < in the HTML stream which did not lead to a tag or comment or other token, it was treating the full text span to that point as one text node, and the following span another text node.

The entire span should be one text node.

In this patch the Tag Processor properly detects this scenario and combines the spans into one text node.

Follow-up to [57348]

Props jonsurrell
Fixes #60385

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/html-api/wpHtmlTagProcessor.php

    r57348 r57489  
    27162716        $this->assertFalse( $result, 'Did not handle "</ " html properly.' );
    27172717    }
     2718
     2719    /**
     2720     * Ensures that non-tag syntax starting with `<` is consumed inside a text node.
     2721     *
     2722     * @ticket 60385
     2723     */
     2724    public function test_single_text_node_with_taglike_text() {
     2725        $p = new WP_HTML_Tag_Processor( 'test< /A>' );
     2726        $p->next_token();
     2727        $this->assertSame( '#text', $p->get_token_type(), 'Did not find text node.' );
     2728        $this->assertSame( 'test< /A>', $p->get_modifiable_text(), 'Did not find complete text node.' );
     2729    }
    27182730}
Note: See TracChangeset for help on using the changeset viewer.