-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTML API: Fix - avoid calling subclass method while internally scanning in Tag Processor #5475
HTML API: Fix - avoid calling subclass method while internally scanning in Tag Processor #5475
Conversation
838f4f4
to
7aebc80
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey this is better than the previous implementation ❤️
7aebc80
to
3026215
Compare
Thanks for the PR! Merged in r56941. |
thanks @SergeyBiryukov! |
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 |
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.
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