Make WordPress Core


Ignore:
Timestamp:
02/22/2023 08:53:41 PM (12 months ago)
Author:
hellofromTonya
Message:

HTML API: Fix finding bookmarks set on closing tag WP_HTML_Tag_Processor.

Setting a bookmark on a tag should set its "start" position before the opening "<", e.g.:

<div> Testing a <b>Bookmark</b>
----------------^

The previous calculation assumed this is always one byte to the left from $tag_name_starts_at.

However, in a closing tag that index points to a solidus symbol "/":

<div> Testing a <b>Bookmark</b>
----------------------------^

The bookmark should therefore start two bytes before the tag name:

<div> Testing a <b>Bookmark</b>
---------------------------^

This changeset achieves this by:

  • Using the correct starting index for closing tag bookmarks.
  • Adding array( 'tag_closers' => 'visit' ) in WP_HTML_Tag_Processor::seek().

Follow-up to [55203].

Props zieladam, dmsnell, flixos90.
Fixes #57787.
See #57575.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/html-api/class-wp-html-tag-processor.php

    r55402 r55407  
    723723
    724724        $this->bookmarks[ $name ] = new WP_HTML_Span(
    725             $this->tag_name_starts_at - 1,
     725            $this->tag_name_starts_at - ( $this->is_closing_tag ? 2 : 1 ),
    726726            $this->tag_ends_at
    727727        );
     
    15051505        $this->bytes_already_copied = $this->bytes_already_parsed;
    15061506        $this->output_buffer        = substr( $this->html, 0, $this->bytes_already_copied );
    1507         return $this->next_tag();
     1507        return $this->next_tag( array( 'tag_closers' => 'visit' ) );
    15081508    }
    15091509
Note: See TracChangeset for help on using the changeset viewer.