Skip to content

Commit 016a29f

Browse files
committed
Merge branch 'html-api/auto-escape-javascript-json' into scripts/use-html-api-for-script-tags
2 parents 5828382 + d8c320c commit 016a29f

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/wp-includes/html-api/class-wp-html-tag-processor.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3868,24 +3868,25 @@ public function set_modifiable_text( string $plaintext_content ): bool {
38683868
* For JavaScript that needs to avoid these issues, workarounds may
38693869
* be available. For example:
38703870
*
3871-
* // Instead of:
3871+
* // Instead of this:
38723872
* const rawStringWillBeEscaped = String.raw`</script>`;
38733873
*
3874-
* // This will yield the same result with no escaping required:
3874+
* // This is a safe alternative:
38753875
* const rawStringWillBePreserved = String.raw`</scr` + String.raw`ipt>`;
38763876
*
3877-
* // After the escaping has been applied and the JavaScript evaluated,
3878-
* // these are the resulting values:
3879-
* rawStringWillBeEscaped; // "</\\u0073cript>"
3880-
* rawStringWillBePreserve; // "</script>"
3877+
* After escaping, the JavaScript result looks like this:
38813878
*
3879+
* const rawStringWillBeEscaped = String.raw`</\u0073cript>`;
3880+
* // Evaluates to `'</\\u0073cript>'`.
3881+
*
3882+
* const rawStringWillBePreserved = String.raw`</scr` + String.raw`ipt>`;
3883+
* // Evaluates to `'</script>'`.
38823884
*
38833885
* Escaping is applied only where strictly necessary, reducing the likelyhood
38843886
* that observable differences manifest in the escaped JavaScript.
38853887
*
3886-
* The alternatives are to reject JavaScript that could be safely escaped in
3887-
* a majority of cases or to relax restrictions in ways that produce dangerous
3888-
* or broken HTML documents, neither are desirable.
3888+
* This escaping strategy strikes will make ALL JavaScript safe to embed in
3889+
* HTML in a way that is completely transparent in most cases.
38893890
*/
38903891
if ( $this->is_javascript_script_tag() ) {
38913892
$plaintext_content = preg_replace_callback(

0 commit comments

Comments
 (0)