Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML API: Prevent bookmarks from being set on virtual tokens #7862

Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/wp-includes/html-api/class-wp-html-processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -5640,6 +5640,9 @@ public function seek( $bookmark_name ): bool {
* @return bool Whether the bookmark was successfully created.
*/
public function set_bookmark( $bookmark_name ): bool {
if ( $this->is_virtual() ) {
sirreal marked this conversation as resolved.
Show resolved Hide resolved
return false;
}
return parent::set_bookmark( "_{$bookmark_name}" );
}

Expand Down
11 changes: 11 additions & 0 deletions tests/phpunit/tests/html-api/wpHtmlProcessor-bookmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,15 @@ public static function data_processor_constructors(): array {
'Fragment parser' => array( array( WP_HTML_Processor::class, 'create_fragment' ) ),
);
}

/**
* @ticket TBD
sirreal marked this conversation as resolved.
Show resolved Hide resolved
*/
gziolo marked this conversation as resolved.
Show resolved Hide resolved
public function test_bookmarks_not_allowed_on_virtual_nodes() {
$processor = WP_HTML_Processor::create_full_parser( 'text' );
$this->assertTrue( $processor->next_tag( 'BODY' ) );
$this->assertFalse( $processor->set_bookmark( 'mark' ) );
$this->assertTrue( $processor->next_token() );
$this->assertTrue( $processor->set_bookmark( 'mark' ) );
}
}
Loading