mirror of
git://develop.git.wordpress.org/
synced 2025-03-22 04:49:49 +01:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@59812 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
64fd288392
commit
8cc8eb5401
@ -2551,6 +2551,15 @@ class WP_HTML_Tag_Processor {
|
||||
return false;
|
||||
}
|
||||
|
||||
$existing_bookmark = $this->bookmarks[ $bookmark_name ];
|
||||
|
||||
if (
|
||||
$this->token_starts_at === $existing_bookmark->start &&
|
||||
$this->token_length === $existing_bookmark->length
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( ++$this->seek_count > static::MAX_SEEK_OPS ) {
|
||||
_doing_it_wrong(
|
||||
__METHOD__,
|
||||
|
@ -435,16 +435,49 @@ HTML;
|
||||
public function test_limits_the_number_of_seek_calls() {
|
||||
$processor = new WP_HTML_Tag_Processor( '<ul><li>One</li><li>Two</li><li>Three</li></ul>' );
|
||||
$processor->next_tag( 'li' );
|
||||
$processor->set_bookmark( 'bookmark' );
|
||||
$processor->set_bookmark( 'ping' );
|
||||
$processor->next_tag( 'li' );
|
||||
$processor->set_bookmark( 'pong' );
|
||||
|
||||
for ( $i = 0; $i < WP_HTML_Tag_Processor::MAX_SEEK_OPS; $i++ ) {
|
||||
$this->assertTrue( $processor->seek( 'bookmark' ), 'Could not seek to the "bookmark"' );
|
||||
for ( $i = 0; $i < WP_HTML_Tag_Processor::MAX_SEEK_OPS; $i += 2 ) {
|
||||
$this->assertTrue(
|
||||
$processor->seek( 'ping' ),
|
||||
'Could not seek to the "ping": check test setup.'
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$processor->seek( 'pong' ),
|
||||
'Could not seek to the "pong": check test setup.'
|
||||
);
|
||||
}
|
||||
|
||||
$this->setExpectedIncorrectUsage( 'WP_HTML_Tag_Processor::seek' );
|
||||
$this->assertFalse( $processor->seek( 'bookmark' ), "$i-th seek() to the bookmark succeeded, even though it should exceed the allowed limit" );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 62085
|
||||
*
|
||||
* @covers WP_HTML_Tag_Processor::seek
|
||||
*/
|
||||
public function test_skips_counting_noop_seek_calls() {
|
||||
$processor = new WP_HTML_Tag_Processor( '<ul><li>One</li><li>Two</li><li>Three</li></ul>' );
|
||||
$processor->next_tag( 'li' );
|
||||
$processor->set_bookmark( 'here' );
|
||||
|
||||
for ( $i = 0; $i < WP_HTML_Tag_Processor::MAX_SEEK_OPS; $i++ ) {
|
||||
$this->assertTrue(
|
||||
$processor->seek( 'here' ),
|
||||
'Could not seek to the "here": check test setup.'
|
||||
);
|
||||
}
|
||||
|
||||
$this->assertTrue(
|
||||
$processor->seek( 'here' ),
|
||||
'Should never fail to seek if the seek is pointing at the current location.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that it's possible to seek to an earlier location in a document even
|
||||
* after reaching the end of a document, when most functionality shuts down.
|
||||
|
Loading…
x
Reference in New Issue
Block a user