From 38be2546ae62ec33184bb9a9b7df5e8193a14ea7 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 24 Sep 2025 17:00:18 +0200 Subject: [PATCH 1/2] Block Bindings: Reuse bookmark instead of releasing --- src/wp-includes/class-wp-block.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/wp-includes/class-wp-block.php b/src/wp-includes/class-wp-block.php index 1c5d47d61aeff..8567005af0dbb 100644 --- a/src/wp-includes/class-wp-block.php +++ b/src/wp-includes/class-wp-block.php @@ -493,20 +493,18 @@ public function replace_rich_text( $rich_text ) { $depth = $this->get_current_depth(); - $this->set_bookmark( '_wp_block_bindings_tag_opener' ); + $this->set_bookmark( '_wp_block_bindings' ); // The bookmark names are prefixed with `_` so the key below has an extra `_`. - $tag_opener = $this->bookmarks['__wp_block_bindings_tag_opener']; + $tag_opener = $this->bookmarks['__wp_block_bindings']; $start = $tag_opener->start + $tag_opener->length; - $this->release_bookmark( '_wp_block_bindings_tag_opener' ); // Find matching tag closer. while ( $this->next_token() && $this->get_current_depth() >= $depth ) { } - $this->set_bookmark( '_wp_block_bindings_tag_closer' ); - $tag_closer = $this->bookmarks['__wp_block_bindings_tag_closer']; + $this->set_bookmark( '_wp_block_bindings' ); + $tag_closer = $this->bookmarks['__wp_block_bindings']; $end = $tag_closer->start; - $this->release_bookmark( '_wp_block_bindings_tag_closer' ); $this->lexical_updates[] = new WP_HTML_Text_Replacement( $start, From 8d7590eeeea8ea4e0e0963ff20bb5775565c4888 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 24 Sep 2025 17:44:50 +0200 Subject: [PATCH 2/2] Verify that the matching tag closer was found --- src/wp-includes/class-wp-block.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/class-wp-block.php b/src/wp-includes/class-wp-block.php index 8567005af0dbb..c9bf70d9e10d1 100644 --- a/src/wp-includes/class-wp-block.php +++ b/src/wp-includes/class-wp-block.php @@ -491,7 +491,8 @@ public function replace_rich_text( $rich_text ) { return false; } - $depth = $this->get_current_depth(); + $depth = $this->get_current_depth(); + $tag_name = $this->get_tag(); $this->set_bookmark( '_wp_block_bindings' ); // The bookmark names are prefixed with `_` so the key below has an extra `_`. @@ -502,6 +503,10 @@ public function replace_rich_text( $rich_text ) { while ( $this->next_token() && $this->get_current_depth() >= $depth ) { } + if ( ! $this->is_tag_closer() || $tag_name !== $this->get_tag() ) { + return false; + } + $this->set_bookmark( '_wp_block_bindings' ); $tag_closer = $this->bookmarks['__wp_block_bindings']; $end = $tag_closer->start;