Make WordPress Core


Ignore:
Timestamp:
12/10/2024 09:11:35 AM (5 months ago)
Author:
gziolo
Message:

HTML API: Prevent bookmarks from being set on virtual tokens

Fixes the issue when an HTML_Processor bookmark was set at a virtual token (a node in the resulting document that does not correspond to an HTML token present in the input string), seek behavior was unreliable.

Props jonsurrell, gziolo.
Fixes #62521.

File:
1 edited

Legend:

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

    r59500 r59502  
    304304
    305305        while ( $context_processor->next_tag() ) {
    306             $context_processor->set_bookmark( 'final_node' );
     306            if ( ! $context_processor->is_virtual() ) {
     307                $context_processor->set_bookmark( 'final_node' );
     308            }
    307309        }
    308310
     
    56745676     * HTML structure or unwanted processing overhead.
    56755677     *
     5678     * Bookmarks cannot be set on tokens that do no appear in the original
     5679     * HTML text. For example, the HTML `<table><td>` stops at tags `TABLE`,
     5680     * `TBODY`, `TR`, and `TD`. The `TBODY` and `TR` tags do not appear in
     5681     * the original HTML and cannot be used as bookmarks.
     5682     *
    56765683     * @since 6.4.0
    56775684     *
     
    56805687     */
    56815688    public function set_bookmark( $bookmark_name ): bool {
     5689        if ( $this->is_virtual() ) {
     5690            _doing_it_wrong(
     5691                __METHOD__,
     5692                __( 'Cannot set bookmarks on tokens that do no appear in the original HTML text.' ),
     5693                '6.8.0'
     5694            );
     5695            return false;
     5696        }
    56825697        return parent::set_bookmark( "_{$bookmark_name}" );
    56835698    }
Note: See TracChangeset for help on using the changeset viewer.