Make WordPress Core


Ignore:
Timestamp:
06/27/2024 08:47:38 PM (11 months ago)
Author:
dmsnell
Message:

HTML API: Report breadcrumbs properly when visiting virtual nodes.

When [58304] introduced the abililty to visit virtual nodes in the HTML document,
those being the nodes which are implied by the HTML but no explicitly present in
the raw text, a bug was introduced in the get_breadcrumbs() method because it
wasn't updated to be aware of the virtual nodes. Therefore it would report the
wrong breadcrumbs for virtual nodes. Since the new get_depth() method is based
on the same logic it was also broken for virtual nodes.

In this patch, the breadcrumbs have been updated to account for the virtual nodes
and the depth method has been updated to rely on the fixed breadcrumb logic.

Developed in https://github.com/WordPress/wordpress-develop/pull/6914
Discussed in https://core.trac.wordpress.org/ticket/61348

Follow-up to [58304].

Props dmsnell, jonsurrell, zieladam.
See #61348.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/html-api/class-wp-html-open-elements.php

    r58441 r58588  
    309309    public function pop() {
    310310        $item = array_pop( $this->stack );
    311 
    312311        if ( null === $item ) {
    313312            return false;
    314313        }
    315314
     315        if ( 'context-node' === $item->bookmark_name ) {
     316            $this->stack[] = $item;
     317            return false;
     318        }
     319
    316320        $this->after_element_pop( $item );
    317321        return true;
     
    330334    public function pop_until( $tag_name ) {
    331335        foreach ( $this->walk_up() as $item ) {
     336            if ( 'context-node' === $item->bookmark_name ) {
     337                return true;
     338            }
     339
    332340            $this->pop();
    333341
     
    370378     */
    371379    public function remove_node( $token ) {
     380        if ( 'context-node' === $token->bookmark_name ) {
     381            return false;
     382        }
     383
    372384        foreach ( $this->walk_up() as $position_from_end => $item ) {
    373385            if ( $token->bookmark_name !== $item->bookmark_name ) {
Note: See TracChangeset for help on using the changeset viewer.