Make WordPress Core

Changeset 59812


Ignore:
Timestamp:
02/11/2025 08:02:29 PM (3 months ago)
Author:
westonruter
Message:

HTML API: Stop counting no-op seek operations against the max seek count.

This allows seek() to be freely called when the current cursor at the provided bookmark.

Props dmsnell, jonsurrell, westonruter.
Fixes #62085.

Location:
trunk
Files:
2 edited

Legend:

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

    r59464 r59812  
    25502550            );
    25512551            return false;
     2552        }
     2553
     2554        $existing_bookmark = $this->bookmarks[ $bookmark_name ];
     2555
     2556        if (
     2557            $this->token_starts_at === $existing_bookmark->start &&
     2558            $this->token_length === $existing_bookmark->length
     2559        ) {
     2560            return true;
    25522561        }
    25532562
  • trunk/tests/phpunit/tests/html-api/wpHtmlTagProcessor-bookmark.php

    r58048 r59812  
    436436        $processor = new WP_HTML_Tag_Processor( '<ul><li>One</li><li>Two</li><li>Three</li></ul>' );
    437437        $processor->next_tag( 'li' );
    438         $processor->set_bookmark( 'bookmark' );
    439 
    440         for ( $i = 0; $i < WP_HTML_Tag_Processor::MAX_SEEK_OPS; $i++ ) {
    441             $this->assertTrue( $processor->seek( 'bookmark' ), 'Could not seek to the "bookmark"' );
     438        $processor->set_bookmark( 'ping' );
     439        $processor->next_tag( 'li' );
     440        $processor->set_bookmark( 'pong' );
     441
     442        for ( $i = 0; $i < WP_HTML_Tag_Processor::MAX_SEEK_OPS; $i += 2 ) {
     443            $this->assertTrue(
     444                $processor->seek( 'ping' ),
     445                'Could not seek to the "ping": check test setup.'
     446            );
     447
     448            $this->assertTrue(
     449                $processor->seek( 'pong' ),
     450                'Could not seek to the "pong": check test setup.'
     451            );
    442452        }
    443453
    444454        $this->setExpectedIncorrectUsage( 'WP_HTML_Tag_Processor::seek' );
    445455        $this->assertFalse( $processor->seek( 'bookmark' ), "$i-th seek() to the bookmark succeeded, even though it should exceed the allowed limit" );
     456    }
     457
     458    /**
     459     * @ticket 62085
     460     *
     461     * @covers WP_HTML_Tag_Processor::seek
     462     */
     463    public function test_skips_counting_noop_seek_calls() {
     464        $processor = new WP_HTML_Tag_Processor( '<ul><li>One</li><li>Two</li><li>Three</li></ul>' );
     465        $processor->next_tag( 'li' );
     466        $processor->set_bookmark( 'here' );
     467
     468        for ( $i = 0; $i < WP_HTML_Tag_Processor::MAX_SEEK_OPS; $i++ ) {
     469            $this->assertTrue(
     470                $processor->seek( 'here' ),
     471                'Could not seek to the "here": check test setup.'
     472            );
     473        }
     474
     475        $this->assertTrue(
     476            $processor->seek( 'here' ),
     477            'Should never fail to seek if the seek is pointing at the current location.'
     478        );
    446479    }
    447480
Note: See TracChangeset for help on using the changeset viewer.