Skip to content

Conversation

sirreal
Copy link
Member

@sirreal sirreal commented Jul 10, 2025

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.

Copy link

Test using WordPress Playground

The 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

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@sirreal sirreal marked this pull request as ready for review July 31, 2025 07:20
@sirreal sirreal requested a review from dmsnell July 31, 2025 07:20
Copy link

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props jonsurrell, dmsnell.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@sirreal sirreal force-pushed the html-api/improve-skip-script-data-len-checks branch from 5d8d080 to 7f1c785 Compare August 5, 2025 15:13
* </script>
* ╰──┬───╯
* $at + 8 additional characters is the minimum length required to skip script data.
*/
Copy link
Member

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).

Copy link
Member Author

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?

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member

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.

@sirreal sirreal force-pushed the html-api/improve-skip-script-data-len-checks branch from 7f1c785 to 4be62b9 Compare August 6, 2025 13:23
@sirreal sirreal requested review from Copilot and dmsnell August 6, 2025 15:35
Copilot

This comment was marked as outdated.

@sirreal
Copy link
Member Author

sirreal commented Aug 6, 2025

I've updated the comment and added a number of tests for different script data states. @dmsnell I'd appreciate if you could take another quick look.

EDIT: Additional review happened in #9397.

@sirreal
Copy link
Member Author

sirreal commented Aug 7, 2025

I've pulled the updated comment and moved the test adjacent to the other script parsing test, things which were noted in #9397.

@sirreal sirreal requested a review from Copilot August 7, 2025 07:18
Copilot

This comment was marked as resolved.

@sirreal sirreal removed the request for review from dmsnell August 7, 2025 07:20
pento pushed a commit that referenced this pull request Aug 7, 2025
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
@sirreal
Copy link
Member Author

sirreal commented Aug 7, 2025

Merged in [60617].

@sirreal sirreal closed this Aug 7, 2025
@sirreal sirreal deleted the html-api/improve-skip-script-data-len-checks branch August 7, 2025 08:32
markjaquith pushed a commit to markjaquith/WordPress that referenced this pull request Aug 7, 2025
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
github-actions bot pushed a commit to platformsh/wordpress-performance that referenced this pull request Aug 7, 2025
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants