HTML API: Fix - avoid calling subclass method while internally scanning in Tag Processor#5475
Closed
dmsnell wants to merge 2 commits intoWordPress:trunkfrom
Closed
HTML API: Fix - avoid calling subclass method while internally scanning in Tag Processor#5475dmsnell wants to merge 2 commits intoWordPress:trunkfrom
dmsnell wants to merge 2 commits intoWordPress:trunkfrom
Conversation
838f4f4 to
7aebc80
Compare
Member
Author
adamziel
approved these changes
Oct 13, 2023
Contributor
adamziel
left a comment
There was a problem hiding this comment.
Hey this is better than the previous implementation ❤️
7aebc80 to
3026215
Compare
Member
|
Thanks for the PR! Merged in r56941. |
Member
Author
|
thanks @SergeyBiryukov! |
Contributor
|
I'm not sure if it's related, but Gutenberg trunk PHP tests have started failing, in particular Could that be related to this change, since There's also a bit of discussion over in the |
dmsnell
added a commit
to dmsnell/wordpress-develop
that referenced
this pull request
Oct 17, 2023
Fixes a bug introduced in WordPress#5475. When applying updates to HTML, one step was left out in WordPress#5475 which updated the position of the end of the current tag. This made it possible to create bookmarks with null or earlier end positions than their start position. This in turn broke the Directive Processor in Gutenberg during the backport of changes from Core into Gutenberg. In this patch, after applying updates, the HTML document is now scanned fully to the end of the current tag, updating the internal pointer to its end, so that nothing else will be broken or misaligned.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Trac ticket: Core-59607
After modifying tags in the HTML API, the Tag Processor backs up to before the tag being modified and then re-parses its attributes. This saves on the code-complexity involved in applying updates, which have already been transformed to "lexical updates" by the time they are applied.
In order to do that,
get_updated_html()callsnext_tag()to reuse its logic. Unfortunately, as a public method, subclasses may change the behavior of that method, and the HTML Processor does just this. It maintains an HTML stack of open elements and when the Tag Processor calls this method to re-scan a tag and its attributes, it leads to a broken stack.To fix this, this patch replaces the call to
next_tag()with a more appropriate reapplication of its internal parsing logic to rescan the tag name and its attributes. Given the limited nature of what's occurring inget_updated_html()this should bring with it certain guarantees that no HTML structure is being changed (that structure will only be changed by subclasses like the HTML Processor).This patch resolves an issue discovered by @adamziel during testing of the HTML Processor.
There is no evidence that this makes a clear impact on performance