Skip to content

Commit 8cf2527

Browse files
committed
Explain simple JSON escaping
1 parent 49a6c81 commit 8cf2527

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3865,9 +3865,19 @@ static function ( $matches ) {
38653865
$plaintext_content
38663866
);
38673867
} elseif ( $this->is_json_script_tag() ) {
3868-
/*
3868+
/**
38693869
* JSON can be safely escaped.
3870+
*
3871+
* The following replacement may appear insuficcient, "<" is replaced
3872+
* with its JSON escape sequence "\u003C" without considering whether
3873+
* the "<" is preceded by an escaping slash. JSON does not support
3874+
* arbitrary character escaping (like JavaScript strings) so "\<"
3875+
* is invalid JSON and would have to be preceded by
3876+
* an escaped backslash: "\\<".
3877+
*
3878+
* @see https://www.json.org/json-en.html
38703879
*/
3880+
38713881
$plaintext_content = strtr(
38723882
$plaintext_content,
38733883
array( '<' => '\\u003C' )

0 commit comments

Comments
 (0)