Make WordPress Core

Changeset 60983

Timestamp:
10/20/2025 09:11:46 AM (5 weeks ago)
Author:
Bernhard Reiter
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-block.php

    r60951 r60983  
    445445                }
    446446
    447                 $depth = $this->get_current_depth();
    448 
    449                 $this->set_bookmark( '_wp_block_bindings_tag_opener' );
     447                $depth    = $this->get_current_depth();
     448                $tag_name = $this->get_tag();
     449
     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.
     
    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(
Note: See TracChangeset for help on using the changeset viewer.