Skip to content

Conversation

@sirreal
Copy link
Member

@sirreal sirreal commented Dec 16, 2025

Includes #10635

Trac ticket:


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.

@github-actions
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.

* Other types of script tags cannot be escaped safely because there is
* no general escaping mechanism for arbitrary types of content.
*/
return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we think about changing the design of the is_javascript_script_tag() methods, we could expose something like a MIME type and allow custom filtering of escapes to allow plugins to provide their own escaping routines rather than reject the updates.

for now I see no reason to block progress for this, especially since we already rejected these contents before, but I think we can imagine a situation where someone can replace their SCRIPT contents and we can perform the <script and </script checks after the filter, and only then reject if nothing was able to escape

$expected = str_replace( "'", '"', "<script src='/main-script-a4.js' id='main-script-a4-js' {$strategy} data-wp-strategy='{$strategy}'></script>" );
$this->assertStringContainsString( $expected, $output, 'Only enqueued dependents should affect the eligible strategy.' );
$expected = "<script src='/main-script-a4.js' id='main-script-a4-js' {$strategy} data-wp-strategy='{$strategy}'></script>";
$this->assertEqualHTMLScriptTagById( $expected, $output, 'Only enqueued dependents should affect the eligible strategy.' );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed this in #10649! but this is big

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These test changes should be extracted to their own PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious why you chose DOT as opposed to Mermaid? I know that GitHub supports Mermaid.

In any case, I'm very impressed that you went to the effort of making a diagram to document this.

Copy link
Member

@dmsnell dmsnell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After analyzing the additional changes in this PR above what #10635 provides, nothing look too complicated. I left a question about responsibility for type errors.

Feel free to nag me after #10635 merges so we can get this in fast.

$processor->next_tag();
foreach ( $attributes as $name => $value ) {
if ( is_string( $value ) || true === $value ) {
$processor->set_attribute( $name, $value );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate this type guarding, but it feels a bit redundant. are we attempting to type-check the filter results or are we trying to guard against sending invalid types to set_attribute()?

it doesn’t currently type-check against a string, but we could add _doing_it_wrong() if we want to incur the runtime cost of type-checking there, which would seem okay.

I just want to question the intent here and the fact that this hides type errors and mistakes in the calling code by skipping over attributes which presumably were supposed to be set.

}
}
$processor->set_modifiable_text( $data );
return "{$processor->get_updated_html()}\n";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question as above

*
* While it may seem tempting to replace the `<` character instead, but doing so
* would break JavaScript syntax. The `<` character is used in comparison operators
* and other JavaScript syntax, so replacing it would break valid JavaScript.j
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* and other JavaScript syntax, so replacing it would break valid JavaScript.j
* and other JavaScript syntax, so replacing it would break valid JavaScript.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@westonruter these are handled in #10635 — might want to avoid scrutinizing the changes too closely that are in that other branch, or scrutinize them there.

* @param string $sourcecode Raw contents intended to be serialized into an HTML SCRIPT element.
* @return string Escaped form of input contents which will not lead to premature closing of the containing SCRIPT element.
*/
public static function escape_javascript_script_contents( string $sourcecode ): string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intended to be public, yes?

* escape (`\u0073`) back into its original plaintext value, but only after having
* been safely extracted from the HTML.
*
* While it may seem tempting to replace the `<` character instead, but doing so
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* While it may seem tempting to replace the `<` character instead, but doing so
* While it may seem tempting to replace the `<` character instead, doing so

Gemini suggests the "but" is redundant. I agree.

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.

3 participants