HTML API: Ensure that `get_modifiable_text()` reads enqueued updates.

When `set_modifiable_text()` was added to the Tag Processor, it was considered that the same information could be queried after setting its value and before proceeding to the next token, but unfortunately overlooked that if the starting modifiable text length was zero, then the read in `get_modifiable_text()` would ignore enqueued updates.

In this patch, `get_modifiable_text()` will read any enqueued values before reading from the input HTML document to ensure consistency.

Follow-up to [58829].
Props dmsnell, jonsurrell, ramonopoly.
Fixes #61617.

Built from https://develop.svn.wordpress.org/trunk@58866


git-svn-id: http://core.svn.wordpress.org/trunk@58262 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
dmsnell 2024-08-08 04:26:13 +00:00
parent 0fca569339
commit f200230d18
2 changed files with 6 additions and 4 deletions

View File

@ -614,7 +614,7 @@ class WP_HTML_Tag_Processor {
* *
* @since 6.5.0 * @since 6.5.0
* *
* @var string * @var int
*/ */
private $text_length; private $text_length;
@ -2894,11 +2894,13 @@ class WP_HTML_Tag_Processor {
* @return string * @return string
*/ */
public function get_modifiable_text(): string { public function get_modifiable_text(): string {
if ( null === $this->text_starts_at || 0 === $this->text_length ) { $has_enqueued_update = isset( $this->lexical_updates['modifiable text'] );
if ( ! $has_enqueued_update && ( null === $this->text_starts_at || 0 === $this->text_length ) ) {
return ''; return '';
} }
$text = isset( $this->lexical_updates['modifiable text'] ) $text = $has_enqueued_update
? $this->lexical_updates['modifiable text']->text ? $this->lexical_updates['modifiable text']->text
: substr( $this->html, $this->text_starts_at, $this->text_length ); : substr( $this->html, $this->text_starts_at, $this->text_length );

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.7-alpha-58865'; $wp_version = '6.7-alpha-58866';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.