Skip to content

Commit d3c1b8b

Browse files
committed
Block Bindings: Polish rich-text attribute replacement code.
In the Block Bindings code introduced to replace rich-text attributes, address feedback to: - reuse an existing bookmark (instead of releasing it), and to - verify that the expected matching tag closer was found. Follow-up to [60684]. Props bernhard-reiter, dmsnell. See #63840. git-svn-id: https://develop.svn.wordpress.org/trunk@60983 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 2c5d575 commit d3c1b8b

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/wp-includes/class-wp-block.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -444,22 +444,25 @@ public function replace_rich_text( $rich_text ) {
444444
return false;
445445
}
446446

447-
$depth = $this->get_current_depth();
447+
$depth = $this->get_current_depth();
448+
$tag_name = $this->get_tag();
448449

449-
$this->set_bookmark( '_wp_block_bindings_tag_opener' );
450+
$this->set_bookmark( '_wp_block_bindings' );
450451
// The bookmark names are prefixed with `_` so the key below has an extra `_`.
451-
$tag_opener = $this->bookmarks['__wp_block_bindings_tag_opener'];
452+
$tag_opener = $this->bookmarks['__wp_block_bindings'];
452453
$start = $tag_opener->start + $tag_opener->length;
453-
$this->release_bookmark( '_wp_block_bindings_tag_opener' );
454454

455455
// Find matching tag closer.
456456
while ( $this->next_token() && $this->get_current_depth() >= $depth ) {
457457
}
458458

459-
$this->set_bookmark( '_wp_block_bindings_tag_closer' );
460-
$tag_closer = $this->bookmarks['__wp_block_bindings_tag_closer'];
459+
if ( ! $this->is_tag_closer() || $tag_name !== $this->get_tag() ) {
460+
return false;
461+
}
462+
463+
$this->set_bookmark( '_wp_block_bindings' );
464+
$tag_closer = $this->bookmarks['__wp_block_bindings'];
461465
$end = $tag_closer->start;
462-
$this->release_bookmark( '_wp_block_bindings_tag_closer' );
463466

464467
$this->lexical_updates[] = new WP_HTML_Text_Replacement(
465468
$start,

0 commit comments

Comments
 (0)