<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[47644] branches/5.3: Customize: Add additional filters to Customizer to prevent JSON corruption.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/47644">47644</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/47644","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>whyisjake</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2020-04-29 16:04:20 +0000 (Wed, 29 Apr 2020)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Customize: Add additional filters to Customizer to prevent JSON corruption.
User: Invalidate `user_activation_key` on password update.
Query: Ensure that only a single post can be returned on date/time based queries.
Block Editor: Coding standards, properly escape class names.
Cache API: Ensure proper escaping around the stats method in the cache API.
Formatting: Expand `sanitize_file_name` to have better support for utf8 characters.

Brings the changes in <a href="https://core.trac.wordpress.org/changeset/47633">[47633]</a>, <a href="https://core.trac.wordpress.org/changeset/47634">[47634]</a>, <a href="https://core.trac.wordpress.org/changeset/47635">[47635]</a>, <a href="https://core.trac.wordpress.org/changeset/47636">[47636]</a>, <a href="https://core.trac.wordpress.org/changeset/47637">[47637]</a>, and <a href="https://core.trac.wordpress.org/changeset/47638">[47638]</a> to the 5.4 branch.

Props: aduth, batmoo, ehti, ellatrix, jorgefilipecosta, nickdaugherty, noisysocks, pento, peterwilsoncc, sergeybiryukov, sstoqnov, talldanwp, westi, westonruter, whyisjake, whyisjake, xknown.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branches53srcwpincludesblocksrssphp">branches/5.3/src/wp-includes/blocks/rss.php</a></li>
<li><a href="#branches53srcwpincludesblockssearchphp">branches/5.3/src/wp-includes/blocks/search.php</a></li>
<li><a href="#branches53srcwpincludescachephp">branches/5.3/src/wp-includes/cache.php</a></li>
<li><a href="#branches53srcwpincludesclasswpcustomizemanagerphp">branches/5.3/src/wp-includes/class-wp-customize-manager.php</a></li>
<li><a href="#branches53srcwpincludesclasswpqueryphp">branches/5.3/src/wp-includes/class-wp-query.php</a></li>
<li><a href="#branches53srcwpincludesformattingphp">branches/5.3/src/wp-includes/formatting.php</a></li>
<li><a href="#branches53srcwpincludespostphp">branches/5.3/src/wp-includes/post.php</a></li>
<li><a href="#branches53srcwpincludesuserphp">branches/5.3/src/wp-includes/user.php</a></li>
<li><a href="#branches53testsphpunittestscustomizemanagerphp">branches/5.3/tests/phpunit/tests/customize/manager.php</a></li>
<li><a href="#branches53testsphpunittestsformattingSanitizeFileNamephp">branches/5.3/tests/phpunit/tests/formatting/SanitizeFileName.php</a></li>
<li><a href="#branches53testsphpunittestsuserphp">branches/5.3/tests/phpunit/tests/user.php</a></li>
</ul>

<h3>Property Changed</h3>
<ul>
<li><a href="#branches53">branches/5.3/</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<span class="cx" style="display: block; padding: 0 10px">Index: branches/5.3
</span><span class="cx" style="display: block; padding: 0 10px">===================================================================
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">--- branches/5.3 2020-04-29 15:52:19 UTC (rev 47643)
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+++ branches/5.3  2020-04-29 16:04:20 UTC (rev 47644)
</ins><a id="branches53"></a>
<div class="propset"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Property changes: branches/5.3</h4>
<pre class="diff"><span>
</span></pre></div>
<a id="svnmergeinfo"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: svn:mergeinfo</h4></div>
<span class="cx" style="display: block; padding: 0 10px"> /branches/3.4:21757
</span><span class="cx" style="display: block; padding: 0 10px"> /branches/4.9:43557,43622
</span><span class="cx" style="display: block; padding: 0 10px"> /branches/5.0:43681-43682,43684-43688,43719-43720,43723,43726-43727,43729-43731,43734-43744,43747,43751-43754,43758,43760-43765,43767-43770,43772,43774-43781,43783,43785,43790-43806,43808-43821,43825,43828,43830-43834,43836-43843,43846-43863,43867-43889,43891-43894,43897-43905,43908-43909,43911-43929,43931-43942,43946-43947,43949-43956,43959-43964,43967-43969,43988,43994,44014,44017,44047,44183,44185,44187-44206,44208-44213,44231-44232,44235,44248,44284,44287-44288
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-/trunk:46583,46605-46606,46613,46616,46656,46658,46665,46668,46676-46677,46700-46703,46705,46707,46709,46711,46713,46715,46719-46720,46722,46724,46738,46745-46748,46753,46756-46758,46761-46762,46765,46770,46772,46779,46782,46786,46788,46793,46795,46797,46809,46813,46815,46817,46822,46824,46832,46835,46837-46838,46840,46842,46844-46845,46849,46851-46852,46854,46856,46858,46860,46862,46864,46866,46868,46870,46872,46874,46883,46885,46887,46902,46965-46969,46973-46974,46976,46981,46997,46999-47001,47010,47040,47070-47073,47136,47289,47313,47318,47341,47412,47418
</del><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/trunk:46583,46605-46606,46613,46616,46656,46658,46665,46668,46676-46677,46700-46703,46705,46707,46709,46711,46713,46715,46719-46720,46722,46724,46738,46745-46748,46753,46756-46758,46761-46762,46765,46770,46772,46779,46782,46786,46788,46793,46795,46797,46809,46813,46815,46817,46822,46824,46832,46835,46837-46838,46840,46842,46844-46845,46849,46851-46852,46854,46856,46858,46860,46862,46864,46866,46868,46870,46872,46874,46883,46885,46887,46902,46965-46969,46973-46974,46976,46981,46997,46999-47001,47010,47040,47070-47073,47136,47289,47313,47318,47341,47412,47418,47633-47638
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="branches53srcwpincludesblocksrssphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/5.3/src/wp-includes/blocks/rss.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/5.3/src/wp-includes/blocks/rss.php       2020-04-29 15:52:19 UTC (rev 47643)
+++ branches/5.3/src/wp-includes/blocks/rss.php 2020-04-29 16:04:20 UTC (rev 47644)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -96,7 +96,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $class .= ' ' . $attributes['className'];
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        $list_items_markup = "<ul class='{$class}'>{$list_items}</ul>";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $list_items_markup = sprintf( "<ul class='%s'>%s</ul>", esc_attr( $class ), $list_items );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        // PHP 5.2 compatibility. See: http://simplepie.org/wiki/faq/i_m_getting_memory_leaks.
</span><span class="cx" style="display: block; padding: 0 10px">        $rss->__destruct();
</span></span></pre></div>
<a id="branches53srcwpincludesblockssearchphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/5.3/src/wp-includes/blocks/search.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/5.3/src/wp-includes/blocks/search.php    2020-04-29 15:52:19 UTC (rev 47643)
+++ branches/5.3/src/wp-includes/blocks/search.php      2020-04-29 16:04:20 UTC (rev 47644)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -52,7 +52,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        return sprintf(
</span><span class="cx" style="display: block; padding: 0 10px">                '<form class="%s" role="search" method="get" action="%s">%s</form>',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $class,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         esc_attr( $class ),
</ins><span class="cx" style="display: block; padding: 0 10px">                 esc_url( home_url( '/' ) ),
</span><span class="cx" style="display: block; padding: 0 10px">                $label_markup . $input_markup . $button_markup
</span><span class="cx" style="display: block; padding: 0 10px">        );
</span></span></pre></div>
<a id="branches53srcwpincludescachephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/5.3/src/wp-includes/cache.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/5.3/src/wp-includes/cache.php    2020-04-29 15:52:19 UTC (rev 47643)
+++ branches/5.3/src/wp-includes/cache.php      2020-04-29 16:04:20 UTC (rev 47644)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -695,7 +695,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                echo '</p>';
</span><span class="cx" style="display: block; padding: 0 10px">                echo '<ul>';
</span><span class="cx" style="display: block; padding: 0 10px">                foreach ( $this->cache as $group => $cache ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        echo "<li><strong>Group:</strong> $group - ( " . number_format( strlen( serialize( $cache ) ) / KB_IN_BYTES, 2 ) . 'k )</li>';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 echo '<li><strong>Group:</strong> ' . esc_html( $group ) . ' - ( ' . number_format( strlen( serialize( $cache ) ) / KB_IN_BYTES, 2 ) . 'k )</li>';
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px">                echo '</ul>';
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span></span></pre></div>
<a id="branches53srcwpincludesclasswpcustomizemanagerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/5.3/src/wp-includes/class-wp-customize-manager.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/5.3/src/wp-includes/class-wp-customize-manager.php       2020-04-29 15:52:19 UTC (rev 47643)
+++ branches/5.3/src/wp-includes/class-wp-customize-manager.php 2020-04-29 16:04:20 UTC (rev 47644)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2923,22 +2923,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">                add_filter( 'wp_save_post_revision_post_has_changed', array( $this, '_filter_revision_post_has_changed' ), 5, 3 );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                /*
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                 * Update the changeset post. The publish_customize_changeset action
-                * will cause the settings in the changeset to be saved via
-                * WP_Customize_Setting::save().
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+          * Update the changeset post. The publish_customize_changeset action will cause the settings in the
+                * changeset to be saved via WP_Customize_Setting::save(). Updating a post with publish status will
+                * trigger WP_Customize_Manager::publish_changeset_values().
</ins><span class="cx" style="display: block; padding: 0 10px">                  */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
-               // Prevent content filters from corrupting JSON in post_content.
-               $has_kses = ( false !== has_filter( 'content_save_pre', 'wp_filter_post_kses' ) );
-               if ( $has_kses ) {
-                       kses_remove_filters();
-               }
-               $has_targeted_link_rel_filters = ( false !== has_filter( 'content_save_pre', 'wp_targeted_link_rel' ) );
-               if ( $has_targeted_link_rel_filters ) {
-                       wp_remove_targeted_link_rel_filters();
-               }
-
-               // Note that updating a post with publish status will trigger WP_Customize_Manager::publish_changeset_values().
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         add_filter( 'wp_insert_post_data', array( $this, 'preserve_insert_changeset_post_content' ), 5, 3 );
</ins><span class="cx" style="display: block; padding: 0 10px">                 if ( $changeset_post_id ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( $args['autosave'] && 'auto-draft' !== get_post_status( $changeset_post_id ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                // See _wp_translate_postdata() for why this is required as it will use the edit_post meta capability.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2965,15 +2954,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                $this->_changeset_post_id = $r; // Update cached post ID for the loaded changeset.
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                remove_filter( 'wp_insert_post_data', array( $this, 'preserve_insert_changeset_post_content' ), 5 );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // Restore removed content filters.
-               if ( $has_kses ) {
-                       kses_init_filters();
-               }
-               if ( $has_targeted_link_rel_filters ) {
-                       wp_init_targeted_link_rel_filters();
-               }
-
</del><span class="cx" style="display: block; padding: 0 10px">                 $this->_changeset_data = null; // Reset so WP_Customize_Manager::changeset_data() will re-populate with updated contents.
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                remove_filter( 'wp_save_post_revision_post_has_changed', array( $this, '_filter_revision_post_has_changed' ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2991,6 +2973,51 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * Preserve the initial JSON post_content passed to save into the post.
+        *
+        * This is needed to prevent KSES and other {@see 'content_save_pre'} filters
+        * from corrupting JSON data.
+        *
+        * Note that WP_Customize_Manager::validate_setting_values() have already
+        * run on the setting values being serialized as JSON into the post content
+        * so it is pre-sanitized.
+        *
+        * Also, the sanitization logic is re-run through the respective
+        * WP_Customize_Setting::sanitize() method when being read out of the
+        * changeset, via WP_Customize_Manager::post_value(), and this sanitized
+        * value will also be sent into WP_Customize_Setting::update() for
+        * persisting to the DB.
+        *
+        * Multiple users can collaborate on a single changeset, where one user may
+        * have the unfiltered_html capability but another may not. A user with
+        * unfiltered_html may add a script tag to some field which needs to be kept
+        * intact even when another user updates the changeset to modify another field
+        * when they do not have unfiltered_html.
+        *
+        * @since 5.4.1
+        *
+        * @param array $data                An array of slashed and processed post data.
+        * @param array $postarr             An array of sanitized (and slashed) but otherwise unmodified post data.
+        * @param array $unsanitized_postarr An array of slashed yet *unsanitized* and unprocessed post data as originally passed to wp_insert_post().
+        * @return array Filtered post data.
+        */
+       public function preserve_insert_changeset_post_content( $data, $postarr, $unsanitized_postarr ) {
+               if (
+                       isset( $data['post_type'] ) &&
+                       isset( $unsanitized_postarr['post_content'] ) &&
+                       'customize_changeset' === $data['post_type'] ||
+                       (
+                               'revision' === $data['post_type'] &&
+                               ! empty( $data['post_parent'] ) &&
+                               'customize_changeset' === get_post_type( $data['post_parent'] )
+                       )
+               ) {
+                       $data['post_content'] = $unsanitized_postarr['post_content'];
+               }
+               return $data;
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * Trash or delete a changeset post.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * The following re-formulates the logic from `wp_trash_post()` as done in
</span></span></pre></div>
<a id="branches53srcwpincludesclasswpqueryphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/5.3/src/wp-includes/class-wp-query.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/5.3/src/wp-includes/class-wp-query.php   2020-04-29 15:52:19 UTC (rev 47643)
+++ branches/5.3/src/wp-includes/class-wp-query.php     2020-04-29 16:04:20 UTC (rev 47644)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -800,10 +800,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->is_single = true;
</span><span class="cx" style="display: block; padding: 0 10px">                } elseif ( $qv['p'] ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->is_single = true;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                } elseif ( ( '' !== $qv['hour'] ) && ( '' !== $qv['minute'] ) && ( '' !== $qv['second'] ) && ( '' != $qv['year'] ) && ( '' != $qv['monthnum'] ) && ( '' != $qv['day'] ) ) {
-                       // If year, month, day, hour, minute, and second are set, a single
-                       // post is being queried.
-                       $this->is_single = true;
</del><span class="cx" style="display: block; padding: 0 10px">                 } elseif ( '' != $qv['pagename'] || ! empty( $qv['page_id'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->is_page   = true;
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->is_single = false;
</span></span></pre></div>
<a id="branches53srcwpincludesformattingphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/5.3/src/wp-includes/formatting.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/5.3/src/wp-includes/formatting.php       2020-04-29 15:52:19 UTC (rev 47643)
+++ branches/5.3/src/wp-includes/formatting.php 2020-04-29 16:04:20 UTC (rev 47644)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2003,6 +2003,24 @@
</span><span class="cx" style="display: block; padding: 0 10px"> function sanitize_file_name( $filename ) {
</span><span class="cx" style="display: block; padding: 0 10px">        $filename_raw  = $filename;
</span><span class="cx" style="display: block; padding: 0 10px">        $special_chars = array( '?', '[', ']', '/', '\\', '=', '<', '>', ':', ';', ',', "'", '"', '&', '$', '#', '*', '(', ')', '|', '~', '`', '!', '{', '}', '%', '+', chr( 0 ) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+       // Check for support for utf8 in the installed PCRE library once and store the result in a static.
+       static $utf8_pcre = null;
+       if ( ! isset( $utf8_pcre ) ) {
+               // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
+               $utf8_pcre = @preg_match( '/^./u', 'a' );
+       }
+
+       if ( ! seems_utf8( $filename ) ) {
+               $_ext     = pathinfo( $filename, PATHINFO_EXTENSION );
+               $_name    = pathinfo( $filename, PATHINFO_FILENAME );
+               $filename = sanitize_title_with_dashes( $_name ) . '.' . $_ext;
+       }
+
+       if ( $utf8_pcre ) {
+               $filename = preg_replace( "#\x{00a0}#siu", ' ', $filename );
+       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">         /**
</span><span class="cx" style="display: block; padding: 0 10px">         * Filters the list of characters to remove from a filename.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2012,7 +2030,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @param string $filename_raw  Filename as it was passed into sanitize_file_name().
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        $special_chars = apply_filters( 'sanitize_file_name_chars', $special_chars, $filename_raw );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        $filename      = preg_replace( "#\x{00a0}#siu", ' ', $filename );
</del><span class="cx" style="display: block; padding: 0 10px">         $filename      = str_replace( $special_chars, '', $filename );
</span><span class="cx" style="display: block; padding: 0 10px">        $filename      = str_replace( array( '%20', '+' ), '-', $filename );
</span><span class="cx" style="display: block; padding: 0 10px">        $filename      = preg_replace( '/[\r\n\t -]+/', '-', $filename );
</span></span></pre></div>
<a id="branches53srcwpincludespostphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/5.3/src/wp-includes/post.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/5.3/src/wp-includes/post.php     2020-04-29 15:52:19 UTC (rev 47643)
+++ branches/5.3/src/wp-includes/post.php       2020-04-29 16:04:20 UTC (rev 47644)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3554,6 +3554,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> function wp_insert_post( $postarr, $wp_error = false ) {
</span><span class="cx" style="display: block; padding: 0 10px">        global $wpdb;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        // Capture original pre-sanitized array for passing into filters.
+       $unsanitized_postarr = $postarr;
+
</ins><span class="cx" style="display: block; padding: 0 10px">         $user_id = get_current_user_id();
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        $defaults = array(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3865,21 +3868,27 @@
</span><span class="cx" style="display: block; padding: 0 10px">                 * Filters attachment post data before it is updated in or added to the database.
</span><span class="cx" style="display: block; padding: 0 10px">                 *
</span><span class="cx" style="display: block; padding: 0 10px">                 * @since 3.9.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 * @since 5.4.1 `$unsanitized_postarr` argument added.
</ins><span class="cx" style="display: block; padding: 0 10px">                  *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                 * @param array $data    An array of sanitized attachment post data.
-                * @param array $postarr An array of unsanitized attachment post data.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+          * @param array $data                An array of slashed, sanitized, and processed attachment post data.
+                * @param array $postarr             An array of slashed and sanitized attachment post data, but not processed.
+                * @param array $unsanitized_postarr An array of slashed yet *unsanitized* and unprocessed attachment post data
+                *                                   as originally passed to wp_insert_post().
</ins><span class="cx" style="display: block; padding: 0 10px">                  */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $data = apply_filters( 'wp_insert_attachment_data', $data, $postarr );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $data = apply_filters( 'wp_insert_attachment_data', $data, $postarr, $unsanitized_postarr );
</ins><span class="cx" style="display: block; padding: 0 10px">         } else {
</span><span class="cx" style="display: block; padding: 0 10px">                /**
</span><span class="cx" style="display: block; padding: 0 10px">                 * Filters slashed post data just before it is inserted into the database.
</span><span class="cx" style="display: block; padding: 0 10px">                 *
</span><span class="cx" style="display: block; padding: 0 10px">                 * @since 2.7.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 * @since 5.4.1 `$unsanitized_postarr` argument added.
</ins><span class="cx" style="display: block; padding: 0 10px">                  *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                 * @param array $data    An array of slashed post data.
-                * @param array $postarr An array of sanitized, but otherwise unmodified post data.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+          * @param array $data                An array of slashed, sanitized, and processed post data.
+                * @param array $postarr             An array of sanitized (and slashed) but otherwise unmodified post data.
+                * @param array $unsanitized_postarr An array of slashed yet *unsanitized* and unprocessed post data as
+                *                                   originally passed to wp_insert_post().
</ins><span class="cx" style="display: block; padding: 0 10px">                  */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $data = apply_filters( 'wp_insert_post_data', $data, $postarr );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $data = apply_filters( 'wp_insert_post_data', $data, $postarr, $unsanitized_postarr );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px">        $data  = wp_unslash( $data );
</span><span class="cx" style="display: block; padding: 0 10px">        $where = array( 'ID' => $post_ID );
</span></span></pre></div>
<a id="branches53srcwpincludesuserphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/5.3/src/wp-includes/user.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/5.3/src/wp-includes/user.php     2020-04-29 15:52:19 UTC (rev 47643)
+++ branches/5.3/src/wp-includes/user.php       2020-04-29 16:04:20 UTC (rev 47644)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1793,7 +1793,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        if ( $update ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( $user_email !== $old_user_data->user_email ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( $user_email !== $old_user_data->user_email || $user_pass !== $old_user_data->user_pass ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $data['user_activation_key'] = '';
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px">                $wpdb->update( $wpdb->users, $data, compact( 'ID' ) );
</span></span></pre></div>
<a id="branches53testsphpunittestscustomizemanagerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/5.3/tests/phpunit/tests/customize/manager.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/5.3/tests/phpunit/tests/customize/manager.php    2020-04-29 15:52:19 UTC (rev 47643)
+++ branches/5.3/tests/phpunit/tests/customize/manager.php      2020-04-29 16:04:20 UTC (rev 47644)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1241,6 +1241,171 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * Test saving changeset post without Kses or other content_save_pre filters mutating content.
+        *
+        * @covers WP_Customize_Manager::save_changeset_post()
+        */
+       public function test_save_changeset_post_without_kses_corrupting_json() {
+               global $wp_customize;
+               $lesser_admin_user_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
+
+               $uuid         = wp_generate_uuid4();
+               $wp_customize = new WP_Customize_Manager(
+                       array(
+                               'changeset_uuid' => $uuid,
+                       )
+               );
+
+               add_filter( 'map_meta_cap', array( $this, 'filter_map_meta_cap_to_disallow_unfiltered_html' ), 10, 2 );
+               kses_init();
+               add_filter( 'content_save_pre', 'capital_P_dangit' );
+               add_post_type_support( 'customize_changeset', 'revisions' );
+
+               $options = array(
+                       'custom_html_1' => '<script>document.write(" Wordpress 1")</script>',
+                       'custom_html_2' => '<script>document.write(" Wordpress 2")</script>',
+                       'custom_html_3' => '<script>document.write(" Wordpress 3")</script>',
+               );
+
+               // Populate setting as user who can bypass content_save_pre filter.
+               wp_set_current_user( self::$admin_user_id );
+               $wp_customize = $this->get_manager_for_testing_json_corruption_protection( $uuid );
+               $wp_customize->set_post_value( 'custom_html_1', $options['custom_html_1'] );
+               $wp_customize->save_changeset_post(
+                       array(
+                               'status' => 'draft',
+                       )
+               );
+
+               // Populate setting as user who cannot bypass content_save_pre filter.
+               wp_set_current_user( $lesser_admin_user_id );
+               $wp_customize = $this->get_manager_for_testing_json_corruption_protection( $uuid );
+               $wp_customize->set_post_value( 'custom_html_2', $options['custom_html_2'] );
+               $wp_customize->save_changeset_post(
+                       array(
+                               'autosave' => true,
+                       )
+               );
+
+               /*
+                * Ensure that the unsanitized value (the "POST data") is preserved in the autosave revision.
+                * The value is sent through the sanitize function when it is read from the changeset.
+                */
+               $autosave_revision = wp_get_post_autosave( $wp_customize->changeset_post_id(), get_current_user_id() );
+               $saved_data        = json_decode( $autosave_revision->post_content, true );
+               $this->assertEquals( $options['custom_html_1'], $saved_data['custom_html_1']['value'] );
+               $this->assertEquals( $options['custom_html_2'], $saved_data['custom_html_2']['value'] );
+
+               // Update post to discard autosave.
+               $wp_customize->save_changeset_post(
+                       array(
+                               'status' => 'draft',
+                       )
+               );
+
+               /*
+                * Ensure that the unsanitized value (the "POST data") is preserved in the post content.
+                * The value is sent through the sanitize function when it is read from the changeset.
+                */
+               $wp_customize = $this->get_manager_for_testing_json_corruption_protection( $uuid );
+               $saved_data   = json_decode( get_post( $wp_customize->changeset_post_id() )->post_content, true );
+               $this->assertEquals( $options['custom_html_1'], $saved_data['custom_html_1']['value'] );
+               $this->assertEquals( $options['custom_html_2'], $saved_data['custom_html_2']['value'] );
+
+               /*
+                * Ensure that the unsanitized value (the "POST data") is preserved in the revisions' content.
+                * The value is sent through the sanitize function when it is read from the changeset.
+                */
+               $revisions  = wp_get_post_revisions( $wp_customize->changeset_post_id() );
+               $revision   = array_shift( $revisions );
+               $saved_data = json_decode( $revision->post_content, true );
+               $this->assertEquals( $options['custom_html_1'], $saved_data['custom_html_1']['value'] );
+               $this->assertEquals( $options['custom_html_2'], $saved_data['custom_html_2']['value'] );
+
+               /*
+                * Now when publishing the changeset, the unsanitized values will be read from the changeset
+                * and sanitized according to the capabilities of the users who originally updated each
+                * setting in the changeset to begin with.
+                */
+               wp_set_current_user( $lesser_admin_user_id );
+               $wp_customize = $this->get_manager_for_testing_json_corruption_protection( $uuid );
+               $wp_customize->set_post_value( 'custom_html_3', $options['custom_html_3'] );
+               $wp_customize->save_changeset_post(
+                       array(
+                               'status' => 'publish',
+                       )
+               );
+
+               // User saved as one who can bypass content_save_pre filter.
+               $this->assertContains( '<script>', get_option( 'custom_html_1' ) );
+               $this->assertContains( 'Wordpress', get_option( 'custom_html_1' ) ); // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled
+
+               // User saved as one who cannot bypass content_save_pre filter.
+               $this->assertNotContains( '<script>', get_option( 'custom_html_2' ) );
+               $this->assertContains( 'WordPress', get_option( 'custom_html_2' ) );
+
+               // User saved as one who also cannot bypass content_save_pre filter.
+               $this->assertNotContains( '<script>', get_option( 'custom_html_3' ) );
+               $this->assertContains( 'WordPress', get_option( 'custom_html_3' ) );
+       }
+
+       /**
+        * Get a manager for testing JSON corruption protection.
+        *
+        * @param string $uuid UUID.
+        * @return WP_Customize_Manager Manager.
+        */
+       private function get_manager_for_testing_json_corruption_protection( $uuid ) {
+               global $wp_customize;
+               $wp_customize = new WP_Customize_Manager(
+                       array(
+                               'changeset_uuid' => $uuid,
+                       )
+               );
+               for ( $i = 0; $i < 5; $i++ ) {
+                       $wp_customize->add_setting(
+                               sprintf( 'custom_html_%d', $i ),
+                               array(
+                                       'type'              => 'option',
+                                       'sanitize_callback' => array( $this, 'apply_content_save_pre_filters_if_not_main_admin_user' ),
+                               )
+                       );
+               }
+               return $wp_customize;
+       }
+
+       /**
+        * Sanitize content with Kses if the current user is not the main admin.
+        *
+        * @since 5.4.1
+        *
+        * @param string $content Content to sanitize.
+        * @return string Sanitized content.
+        */
+       public function apply_content_save_pre_filters_if_not_main_admin_user( $content ) {
+               if ( get_current_user_id() !== self::$admin_user_id ) {
+                       $content = apply_filters( 'content_save_pre', $content );
+               }
+               return $content;
+       }
+
+       /**
+        * Filter map_meta_cap to disallow unfiltered_html.
+        *
+        * @since 5.4.1
+        *
+        * @param array  $caps User's capabilities.
+        * @param string $cap  Requested cap.
+        * @return array Caps.
+        */
+       public function filter_map_meta_cap_to_disallow_unfiltered_html( $caps, $cap ) {
+               if ( 'unfiltered_html' === $cap ) {
+                       $caps = array( 'do_not_allow' );
+               }
+               return $caps;
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * Call count for customize_changeset_save_data filter.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @var int
</span></span></pre></div>
<a id="branches53testsphpunittestsformattingSanitizeFileNamephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/5.3/tests/phpunit/tests/formatting/SanitizeFileName.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/5.3/tests/phpunit/tests/formatting/SanitizeFileName.php  2020-04-29 15:52:19 UTC (rev 47643)
+++ branches/5.3/tests/phpunit/tests/formatting/SanitizeFileName.php    2020-04-29 16:04:20 UTC (rev 47644)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -68,4 +68,20 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Test a filenames that becomes extensionless.
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( 'no-extension', sanitize_file_name( '_.no-extension' ) );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+       /**
+        * @dataProvider data_wp_filenames
+        */
+       function test_replaces_invalid_utf8_characters( $input, $expected ) {
+               $this->assertEquals( $expected, sanitize_file_name( $input ) );
+       }
+
+       function data_wp_filenames() {
+               return array(
+                       array( urldecode( '%B1myfile.png' ), 'myfile.png' ),
+                       array( urldecode( '%B1myfile' ), 'myfile' ),
+                       array( 'demo bar.png', 'demo-bar.png' ),
+                       array( 'demo' . json_decode( '"\u00a0"' ) . 'bar.png', 'demo-bar.png' ),
+               );
+       }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="branches53testsphpunittestsuserphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/5.3/tests/phpunit/tests/user.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/5.3/tests/phpunit/tests/user.php 2020-04-29 15:52:19 UTC (rev 47643)
+++ branches/5.3/tests/phpunit/tests/user.php   2020-04-29 16:04:20 UTC (rev 47644)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1025,7 +1025,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( $u, wp_cache_get( $updated_user->user_nicename, 'userslugs' ) );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        function test_changing_email_invalidates_password_reset_key() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function test_changing_email_invalidates_password_reset_key() {
</ins><span class="cx" style="display: block; padding: 0 10px">                 global $wpdb;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $user = $this->author;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1057,6 +1057,26 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEmpty( $user->user_activation_key );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        public function test_changing_password_invalidates_password_reset_key() {
+               global $wpdb;
+
+               $user = $this->author;
+               $wpdb->update( $wpdb->users, array( 'user_activation_key' => 'key' ), array( 'ID' => $user->ID ) );
+               clean_user_cache( $user );
+
+               $user = get_userdata( $user->ID );
+               $this->assertEquals( 'key', $user->user_activation_key );
+
+               $userdata = array(
+                       'ID'        => $user->ID,
+                       'user_pass' => 'password',
+               );
+               wp_update_user( $userdata );
+
+               $user = get_userdata( $user->ID );
+               $this->assertEmpty( $user->user_activation_key );
+       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">         public function test_search_users_login() {
</span><span class="cx" style="display: block; padding: 0 10px">                $users = get_users(
</span><span class="cx" style="display: block; padding: 0 10px">                        array(
</span></span></pre>
</div>
</div>

</body>
</html>