Media: Prevent decoding attribute corrupting JSON data.

Workaround `wp_img_tag_add_decoding_attr()` potentially breaking JavaScript and JSON data by limiting the addition of the decoding attribute to image tags using unescaped double quoted attributes `src` attributes.

Props rodricus, TimothyBlynJacobs, joelmadigan, mw108, adamsilverstein, flixos90, desrosj, mukesh27.
Fixes #56969.

Built from https://develop.svn.wordpress.org/trunk@54802


git-svn-id: http://core.svn.wordpress.org/trunk@54354 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Peter Wilson 2022-11-11 01:01:12 +00:00
parent 9a2189e880
commit 3151be6da7
2 changed files with 7 additions and 1 deletions

View File

@ -1962,6 +1962,12 @@ function wp_img_tag_add_loading_attr( $image, $context ) {
* @return string Converted `img` tag with `decoding` attribute added.
*/
function wp_img_tag_add_decoding_attr( $image, $context ) {
// Only apply the decoding attribute to images that have a src attribute that
// starts with a double quote, ensuring escaped JSON is also excluded.
if ( false === strpos( $image, ' src="' ) ) {
return $image;
}
/**
* Filters the `decoding` attribute value to add to an image. Default `async`.
*

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.2-alpha-54801';
$wp_version = '6.2-alpha-54802';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.