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. Built from https://develop.svn.wordpress.org/trunk@59502 git-svn-id: http://core.svn.wordpress.org/trunk@58888 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -303,7 +303,9 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor {
|
||||
}
|
||||
|
||||
while ( $context_processor->next_tag() ) {
|
||||
$context_processor->set_bookmark( 'final_node' );
|
||||
if ( ! $context_processor->is_virtual() ) {
|
||||
$context_processor->set_bookmark( 'final_node' );
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
@@ -5673,12 +5675,25 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor {
|
||||
* reaching for it, as inappropriate use could lead to broken
|
||||
* HTML structure or unwanted processing overhead.
|
||||
*
|
||||
* Bookmarks cannot be set on tokens that do no appear in the original
|
||||
* HTML text. For example, the HTML `<table><td>` stops at tags `TABLE`,
|
||||
* `TBODY`, `TR`, and `TD`. The `TBODY` and `TR` tags do not appear in
|
||||
* the original HTML and cannot be used as bookmarks.
|
||||
*
|
||||
* @since 6.4.0
|
||||
*
|
||||
* @param string $bookmark_name Identifies this particular bookmark.
|
||||
* @return bool Whether the bookmark was successfully created.
|
||||
*/
|
||||
public function set_bookmark( $bookmark_name ): bool {
|
||||
if ( $this->is_virtual() ) {
|
||||
_doing_it_wrong(
|
||||
__METHOD__,
|
||||
__( 'Cannot set bookmarks on tokens that do no appear in the original HTML text.' ),
|
||||
'6.8.0'
|
||||
);
|
||||
return false;
|
||||
}
|
||||
return parent::set_bookmark( "_{$bookmark_name}" );
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.8-alpha-59501';
|
||||
$wp_version = '6.8-alpha-59502';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
||||
Reference in New Issue
Block a user