-
Notifications
You must be signed in to change notification settings - Fork 3.1k
HTML API: Reduce skip_script_data length checks #9230
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: Reduce skip_script_data length checks #9230
Conversation
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
5d8d080
to
7f1c785
Compare
* </script> | ||
* ╰──┬───╯ | ||
* $at + 8 additional characters is the minimum length required to skip script data. | ||
*/ |
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.
this patch is good, but before we merge, can we also note in this comment that we’re looking for other strings and they are covered here? I think the comment at the moment is slightly misleading, but we also check for <!--
for instance, and it’s currently incidental I think that terminating false
is the same for all places within the SCRIPT.
imagine, however, that we wanted to signal something different if we failed to exit the SCRIPT because there was no end-tag vs. that we ended inside some escaped state? then, by returning early at this point we removed our ability to find the <!--
that transitions state.
I believe in review that the code is solid, but I want to make sure we leave this note for the future as a warning to reconsider the check if changing things. I don’t know that these are all currently caught in the tests (which of course would be another great way to cover this risk, by adding new tests for each of these cases, if we can properly think them up).
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.
Good point, I've updated the comment to clarify things.
I do have a number of tests to add to this. I can push them to this branch.
Given how complicated script tag parsing is, I'm tempted to extract them to their own test suite like wpHtmlTagProcessor-scriptParsing
. Do you have thoughts on that?
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.
I pulled in your comment changes from #9397 and made some further tweaks. I'm pretty happy with it now.
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.
your third example in the comment is perfect. I was probably lazy in not suggesting that in my comment.
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.
extract them to their own test suite like wpHtmlTagProcessor-scriptParsing. Do you have thoughts on that?
not that I consider it a huge priority, but I think this is a great idea and would make it clearer for us to be more comprehensive in the tests. I think for every branch of the state machine in the HTML spec we could have data providers generating example inputs for them.
The parser state is managed externally and should not be changed in skip_script_data
7f1c785
to
4be62b9
Compare
I've pulled the updated comment and moved the test adjacent to the other script parsing test, things which were noted in #9397. |
Apply an optimization to remove several repeated string length checks in `WP_HTML_Tag_Processor::skip_script_data()`. Developed in #9230. Props jonsurrell, dmsnell. See #63738. git-svn-id: https://develop.svn.wordpress.org/trunk@60617 602fd350-edb4-49c9-b593-d223f7449a82
Merged in [60617]. |
Apply an optimization to remove several repeated string length checks in `WP_HTML_Tag_Processor::skip_script_data()`. Developed in WordPress/wordpress-develop#9230. Props jonsurrell, dmsnell. See #63738. Built from https://develop.svn.wordpress.org/trunk@60617 git-svn-id: http://core.svn.wordpress.org/trunk@59953 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Apply an optimization to remove several repeated string length checks in `WP_HTML_Tag_Processor::skip_script_data()`. Developed in WordPress/wordpress-develop#9230. Props jonsurrell, dmsnell. See #63738. Built from https://develop.svn.wordpress.org/trunk@60617 git-svn-id: https://core.svn.wordpress.org/trunk@59953 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Trac ticket: Core-63738
Reduce the number of length checks in
WP_HTML_Tag_Processor::skip_script_data()
.This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.