Commit c6d19b0353 for wordpress.org
commit c6d19b0353ee377cdf9c424725c64e7e682de04b
Author: dmsnell <dmsnell@git.wordpress.org>
Date: Wed Oct 28 23:19:04 2026 +0000
Blocks: Fix advancement inside `extract_full_block_and_advance()`.
When the Block Processor was introduced, the `extract_full_block_and_advance()` method was provided in order to support backwards compatibility with `parse_blocks()`, specifically when wanting to extract the structural representation of a subset of blocks within a large post.
Unfortunately, when extracting void blocks, it was advancing to the next token, which, if called from within a loop that was already advancing, would lead to a skipped block delimiter.
In this patch the behavior is normalized such that, after a call to `extract_full_block_and_advance()`, the calling code should call `next_token()` to continue processing the next block or top-level freeform HTML in the post.
Developed in: https://github.com/WordPress/wordpress-develop/pull/14104
Discussed in: https://core.trac.wordpress.org/ticket/66138
Follow-up to r60939.
Props dmsnell, jonsurrell, westonruter.
See #66138.
Built from https://develop.svn.wordpress.org/trunk@64994
git-svn-id: http://core.svn.wordpress.org/trunk@64144 1a063a9b-81f0-0310-95a4-ce76da25c4cd
diff --git a/wp-includes/class-wp-block-processor.php b/wp-includes/class-wp-block-processor.php
index b62bb1c511..7ad4de1f2d 100644
--- a/wp-includes/class-wp-block-processor.php
+++ b/wp-includes/class-wp-block-processor.php
@@ -1314,6 +1314,10 @@ class WP_Block_Processor {
'innerContent' => array(),
);
+ if ( self::VOID === $this->get_delimiter_type() ) {
+ return $block;
+ }
+
$depth = $this->get_depth();
while ( $this->next_token() && $this->get_depth() > $depth ) {
if ( $this->is_html() ) {
@@ -1334,17 +1338,6 @@ class WP_Block_Processor {
$block['innerBlocks'][] = $inner_block;
$block['innerContent'][] = null;
}
-
- /*
- * Because the parser has advanced past the closing block token, it
- * may be matched on an HTML span. This needs to be processed before
- * moving on to the next token at the start of the next loop iteration.
- */
- if ( $this->is_html() ) {
- $chunk = $this->get_html_content();
- $block['innerHTML'] .= $chunk;
- $block['innerContent'][] = $chunk;
- }
}
return $block;
@@ -1650,6 +1643,8 @@ class WP_Block_Processor {
* @see self::is_non_whitespace_html()
*
* @return bool Whether the processor is matched on an HTML span.
+ *
+ * @phpstan-impure
*/
public function is_html(): bool {
return self::HTML_SPAN === $this->state;
diff --git a/wp-includes/version.php b/wp-includes/version.php
index c365424f8e..f5bf154142 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
-$wp_version = '7.2-beta3-64993';
+$wp_version = '7.2-beta3-64994';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.