Skip to content

Commit

Permalink
Call internal parsing methods instead of public next_tag() after up…
Browse files Browse the repository at this point in the history
…dating HTML.
  • Loading branch information
dmsnell committed Oct 12, 2023
1 parent 1d45bdd commit 7aebc80
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/wp-includes/html-api/class-wp-html-tag-processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -2270,6 +2270,7 @@ public function __toString() {
*
* @since 6.2.0
* @since 6.2.1 Shifts the internal cursor corresponding to the applied updates.
* @since 6.5.0 No longer calls subclass method `next_tag()` after updating HTML.
*
* @return string The processed HTML.
*/
Expand Down Expand Up @@ -2303,24 +2304,23 @@ public function get_updated_html() {
* Rewind before the tag name starts so that it's as if the cursor didn't
* move; a call to `next_tag()` will reparse the recently-updated attributes
* and additional calls to modify the attributes will apply at this same
* location.
* location, but in order to avoid issues with subclasses that might add
* behaviors to `next_tag()`, the internal methods should be called here
* instead. It's important to note that in this specific place there will
* be no change because the processor was already at a tag when this was
* called and it's rewinding only to the beginning of this very tag before
* reprocessing it and its attributes.
*
* <p>Previous HTML<em>More HTML</em></p>
* ^ | back up by the length of the tag name plus the opening <
* \<-/ back up by strlen("em") + 1 ==> 3
* ↑ │ back up by the length of the tag name plus the opening <
* └←─┘ back up by strlen("em") + 1 ==> 3
*/

// Store existing state so it can be restored after reparsing.
$previous_parsed_byte_count = $this->bytes_already_parsed;
$previous_query = $this->last_query;

// Reparse attributes.
$this->bytes_already_parsed = $before_current_tag;
$this->next_tag();

// Restore previous state.
$this->bytes_already_parsed = $previous_parsed_byte_count;
$this->parse_query( $previous_query );
$this->parse_next_tag();
// Reparse the attributes.
while ( $this->parse_next_attribute() ) {
continue;
}

return $this->html;
}
Expand Down

0 comments on commit 7aebc80

Please sign in to comment.