<!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>[57750] trunk: Query: Remove leading whitespace from certain database queries.</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/57750">57750</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/57750","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>swissspidy</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2024-03-02 13:36:02 +0000 (Sat, 02 Mar 2024)</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'>Query: Remove leading whitespace from certain database queries.
Unintended leading whitespace at the beginning of a raw MySQL query led to unexpected behavior such as broken pagination. Eliminating said whitespace avoids that.
Adds unit tests to prevent regressions.
Props wpfed, swissspidy, ironprogrammer, tadamarketing, afercia.
Fixes <a href="https://core.trac.wordpress.org/ticket/56841">#56841</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesclasswpcommentqueryphp">trunk/src/wp-includes/class-wp-comment-query.php</a></li>
<li><a href="#trunksrcwpincludesclasswpnetworkqueryphp">trunk/src/wp-includes/class-wp-network-query.php</a></li>
<li><a href="#trunksrcwpincludesclasswpqueryphp">trunk/src/wp-includes/class-wp-query.php</a></li>
<li><a href="#trunksrcwpincludesclasswpsitequeryphp">trunk/src/wp-includes/class-wp-site-query.php</a></li>
<li><a href="#trunksrcwpincludesclasswptermqueryphp">trunk/src/wp-includes/class-wp-term-query.php</a></li>
<li><a href="#trunksrcwpincludesclasswpuserqueryphp">trunk/src/wp-includes/class-wp-user-query.php</a></li>
<li><a href="#trunktestsphpunittestscommentqueryphp">trunk/tests/phpunit/tests/comment/query.php</a></li>
<li><a href="#trunktestsphpunittestsmultisitewpNetworkQueryphp">trunk/tests/phpunit/tests/multisite/wpNetworkQuery.php</a></li>
<li><a href="#trunktestsphpunittestsmultisitewpSiteQueryphp">trunk/tests/phpunit/tests/multisite/wpSiteQuery.php</a></li>
<li><a href="#trunktestsphpunittestspostqueryphp">trunk/tests/phpunit/tests/post/query.php</a></li>
<li><a href="#trunktestsphpunitteststermqueryphp">trunk/tests/phpunit/tests/term/query.php</a></li>
<li><a href="#trunktestsphpunittestsuserqueryphp">trunk/tests/phpunit/tests/user/query.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesclasswpcommentqueryphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-comment-query.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-comment-query.php 2024-03-02 12:53:53 UTC (rev 57749)
+++ trunk/src/wp-includes/class-wp-comment-query.php 2024-03-02 13:36:02 UTC (rev 57750)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -964,14 +964,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->sql_clauses['orderby'] = $orderby;
</span><span class="cx" style="display: block; padding: 0 10px"> $this->sql_clauses['limits'] = $limits;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->request = "
- {$this->sql_clauses['select']}
- {$this->sql_clauses['from']}
- {$where}
- {$this->sql_clauses['groupby']}
- {$this->sql_clauses['orderby']}
- {$this->sql_clauses['limits']}
- ";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Beginning of the string is on a new line to prevent leading whitespace. See https://core.trac.wordpress.org/ticket/56841.
+ $this->request =
+ "{$this->sql_clauses['select']}
+ {$this->sql_clauses['from']}
+ {$where}
+ {$this->sql_clauses['groupby']}
+ {$this->sql_clauses['orderby']}
+ {$this->sql_clauses['limits']}";
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $this->query_vars['count'] ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return (int) $wpdb->get_var( $this->request );
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpnetworkqueryphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-network-query.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-network-query.php 2024-03-02 12:53:53 UTC (rev 57749)
+++ trunk/src/wp-includes/class-wp-network-query.php 2024-03-02 13:36:02 UTC (rev 57750)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -481,14 +481,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->sql_clauses['orderby'] = $orderby;
</span><span class="cx" style="display: block; padding: 0 10px"> $this->sql_clauses['limits'] = $limits;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->request = "
- {$this->sql_clauses['select']}
- {$this->sql_clauses['from']}
- {$where}
- {$this->sql_clauses['groupby']}
- {$this->sql_clauses['orderby']}
- {$this->sql_clauses['limits']}
- ";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Beginning of the string is on a new line to prevent leading whitespace. See https://core.trac.wordpress.org/ticket/56841.
+ $this->request =
+ "{$this->sql_clauses['select']}
+ {$this->sql_clauses['from']}
+ {$where}
+ {$this->sql_clauses['groupby']}
+ {$this->sql_clauses['orderby']}
+ {$this->sql_clauses['limits']}";
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $this->query_vars['count'] ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return (int) $wpdb->get_var( $this->request );
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpqueryphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-query.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-query.php 2024-03-02 12:53:53 UTC (rev 57749)
+++ trunk/src/wp-includes/class-wp-query.php 2024-03-02 13:36:02 UTC (rev 57750)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3104,14 +3104,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $found_rows = 'SQL_CALC_FOUND_ROWS';
</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">- $old_request = "
- SELECT $found_rows $distinct $fields
- FROM {$wpdb->posts} $join
- WHERE 1=1 $where
- $groupby
- $orderby
- $limits
- ";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Beginning of the string is on a new line to prevent leading whitespace. See https://core.trac.wordpress.org/ticket/56841.
+ $old_request =
+ "SELECT $found_rows $distinct $fields
+ FROM {$wpdb->posts} $join
+ WHERE 1=1 $where
+ $groupby
+ $orderby
+ $limits";
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->request = $old_request;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3307,14 +3307,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $split_the_query ) {
</span><span class="cx" style="display: block; padding: 0 10px"> // First get the IDs and then fill in the objects.
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->request = "
- SELECT $found_rows $distinct {$wpdb->posts}.ID
- FROM {$wpdb->posts} $join
- WHERE 1=1 $where
- $groupby
- $orderby
- $limits
- ";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Beginning of the string is on a new line to prevent leading whitespace. See https://core.trac.wordpress.org/ticket/56841.
+ $this->request =
+ "SELECT $found_rows $distinct {$wpdb->posts}.ID
+ FROM {$wpdb->posts} $join
+ WHERE 1=1 $where
+ $groupby
+ $orderby
+ $limits";
</ins><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"> * Filters the Post IDs SQL request before sending.
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpsitequeryphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-site-query.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-site-query.php 2024-03-02 12:53:53 UTC (rev 57749)
+++ trunk/src/wp-includes/class-wp-site-query.php 2024-03-02 13:36:02 UTC (rev 57750)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -695,14 +695,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->sql_clauses['orderby'] = $orderby;
</span><span class="cx" style="display: block; padding: 0 10px"> $this->sql_clauses['limits'] = $limits;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->request = "
- {$this->sql_clauses['select']}
- {$this->sql_clauses['from']}
- {$where}
- {$this->sql_clauses['groupby']}
- {$this->sql_clauses['orderby']}
- {$this->sql_clauses['limits']}
- ";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Beginning of the string is on a new line to prevent leading whitespace. See https://core.trac.wordpress.org/ticket/56841.
+ $this->request =
+ "{$this->sql_clauses['select']}
+ {$this->sql_clauses['from']}
+ {$where}
+ {$this->sql_clauses['groupby']}
+ {$this->sql_clauses['orderby']}
+ {$this->sql_clauses['limits']}";
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $this->query_vars['count'] ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return (int) $wpdb->get_var( $this->request );
</span></span></pre></div>
<a id="trunksrcwpincludesclasswptermqueryphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-term-query.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-term-query.php 2024-03-02 12:53:53 UTC (rev 57749)
+++ trunk/src/wp-includes/class-wp-term-query.php 2024-03-02 13:36:02 UTC (rev 57750)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -752,13 +752,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->sql_clauses['orderby'] = $orderby ? "$orderby $order" : '';
</span><span class="cx" style="display: block; padding: 0 10px"> $this->sql_clauses['limits'] = $limits;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->request = "
- {$this->sql_clauses['select']}
- {$this->sql_clauses['from']}
- {$where}
- {$this->sql_clauses['orderby']}
- {$this->sql_clauses['limits']}
- ";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Beginning of the string is on a new line to prevent leading whitespace. See https://core.trac.wordpress.org/ticket/56841.
+ $this->request =
+ "{$this->sql_clauses['select']}
+ {$this->sql_clauses['from']}
+ {$where}
+ {$this->sql_clauses['orderby']}
+ {$this->sql_clauses['limits']}";
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->terms = null;
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpuserqueryphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-user-query.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-user-query.php 2024-03-02 12:53:53 UTC (rev 57749)
+++ trunk/src/wp-includes/class-wp-user-query.php 2024-03-02 13:36:02 UTC (rev 57750)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -818,13 +818,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->results = apply_filters_ref_array( 'users_pre_query', array( null, &$this ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( null === $this->results ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->request = "
- SELECT {$this->query_fields}
- {$this->query_from}
- {$this->query_where}
- {$this->query_orderby}
- {$this->query_limit}
- ";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Beginning of the string is on a new line to prevent leading whitespace. See https://core.trac.wordpress.org/ticket/56841.
+ $this->request =
+ "SELECT {$this->query_fields}
+ {$this->query_from}
+ {$this->query_where}
+ {$this->query_orderby}
+ {$this->query_limit}";
</ins><span class="cx" style="display: block; padding: 0 10px"> $cache_value = false;
</span><span class="cx" style="display: block; padding: 0 10px"> $cache_key = $this->generate_cache_key( $qv, $this->request );
</span><span class="cx" style="display: block; padding: 0 10px"> $cache_group = 'user-queries';
</span></span></pre></div>
<a id="trunktestsphpunittestscommentqueryphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/comment/query.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/comment/query.php 2024-03-02 12:53:53 UTC (rev 57749)
+++ trunk/tests/phpunit/tests/comment/query.php 2024-03-02 13:36:02 UTC (rev 57750)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5350,4 +5350,26 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertNotSame( "Column 'comment_ID' in where clause is ambiguous", $wpdb->last_error );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertStringNotContainsString( ' comment_ID ', $wpdb->last_query );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ /**
+ * @ticket 56841
+ */
+ public function test_query_does_not_have_leading_whitespace() {
+ self::factory()->comment->create(
+ array(
+ 'comment_post_ID' => self::$post_id,
+ 'user_id' => 7,
+ )
+ );
+
+ $q = new WP_Comment_Query();
+ $q->query(
+ array(
+ 'count' => true,
+ 'orderby' => 'none',
+ )
+ );
+
+ $this->assertSame( ltrim( $q->request ), $q->request, 'The query has leading whitespace' );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunktestsphpunittestsmultisitewpNetworkQueryphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/multisite/wpNetworkQuery.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/multisite/wpNetworkQuery.php 2024-03-02 12:53:53 UTC (rev 57749)
+++ trunk/tests/phpunit/tests/multisite/wpNetworkQuery.php 2024-03-02 13:36:02 UTC (rev 57750)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -608,6 +608,23 @@
</span><span class="cx" style="display: block; padding: 0 10px"> public static function filter_networks_pre_query_and_set_networks( $networks, $query ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return array( get_network( self::$network_ids['wordpress.org/'] ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ /**
+ * @ticket 56841
+ */
+ public function test_wp_network_query_does_not_have_leading_whitespace() {
+ $q = new WP_Network_Query();
+ $q->query(
+ array(
+ 'fields' => 'all',
+ 'number' => 3,
+ 'order' => 'ASC',
+ 'update_network_cache' => true,
+ )
+ );
+
+ $this->assertSame( ltrim( $q->request ), $q->request, 'The query has leading whitespace' );
+ }
</ins><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"> endif;
</span></span></pre></div>
<a id="trunktestsphpunittestsmultisitewpSiteQueryphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/multisite/wpSiteQuery.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/multisite/wpSiteQuery.php 2024-03-02 12:53:53 UTC (rev 57749)
+++ trunk/tests/phpunit/tests/multisite/wpSiteQuery.php 2024-03-02 13:36:02 UTC (rev 57750)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1162,6 +1162,26 @@
</span><span class="cx" style="display: block; padding: 0 10px"> public static function filter_sites_pre_query_and_set_sites( $sites, $query ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return array( get_site( self::$site_ids['wordpress.org/'] ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ /**
+ * @ticket 56841
+ */
+ public function test_wp_site_query_does_not_have_leading_whitespace() {
+ $q = new WP_Site_Query();
+
+ $q->query(
+ array(
+ 'fields' => 'ids',
+ 'network_id' => self::$network_ids['wordpress.org/'],
+ 'number' => 3,
+ 'order' => 'ASC',
+ 'update_site_cache' => true,
+ 'update_site_meta_cache' => true,
+ )
+ );
+
+ $this->assertSame( ltrim( $q->request ), $q->request, 'The query has leading whitespace' );
+ }
</ins><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"> endif;
</span></span></pre></div>
<a id="trunktestsphpunittestspostqueryphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/post/query.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/post/query.php 2024-03-02 12:53:53 UTC (rev 57749)
+++ trunk/tests/phpunit/tests/post/query.php 2024-03-02 13:36:02 UTC (rev 57750)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -792,4 +792,38 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertSame( (bool) wp_using_ext_object_cache(), $filter->get_args()[0][0] );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ /**
+ * @ticket 56841
+ */
+ public function test_query_does_not_have_leading_whitespace() {
+ add_filter( 'split_the_query', '__return_false' );
+
+ $q = new WP_Query(
+ array(
+ 'posts_per_page' => 501,
+ )
+ );
+
+ remove_filter( 'split_the_query', '__return_false' );
+
+ $this->assertSame( ltrim( $q->request ), $q->request, 'The query has leading whitespace' );
+ }
+
+ /**
+ * @ticket 56841
+ */
+ public function test_query_does_not_have_leading_whitespace_split_the_query() {
+ add_filter( 'split_the_query', '__return_true' );
+
+ $q = new WP_Query(
+ array(
+ 'posts_per_page' => 501,
+ )
+ );
+
+ remove_filter( 'split_the_query', '__return_true' );
+
+ $this->assertSame( ltrim( $q->request ), $q->request, 'The query has leading whitespace' );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunktestsphpunitteststermqueryphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/term/query.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/term/query.php 2024-03-02 12:53:53 UTC (rev 57749)
+++ trunk/tests/phpunit/tests/term/query.php 2024-03-02 13:36:02 UTC (rev 57750)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1123,4 +1123,19 @@
</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">+
+ /**
+ * @ticket 56841
+ */
+ public function test_query_does_not_have_leading_whitespace() {
+ $q = new WP_Term_Query(
+ array(
+ 'taxonomy' => 'wptests_tax',
+ 'hide_empty' => true,
+ 'fields' => 'ids',
+ )
+ );
+
+ $this->assertSame( ltrim( $q->request ), $q->request, 'The query has leading whitespace' );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunktestsphpunittestsuserqueryphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/user/query.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/user/query.php 2024-03-02 12:53:53 UTC (rev 57749)
+++ trunk/tests/phpunit/tests/user/query.php 2024-03-02 13:36:02 UTC (rev 57750)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2378,4 +2378,17 @@
</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">+
+ /**
+ * @ticket 56841
+ */
+ public function test_query_does_not_have_leading_whitespace() {
+ $q = new WP_User_Query(
+ array(
+ 'number' => 2,
+ )
+ );
+
+ $this->assertSame( ltrim( $q->request ), $q->request, 'The query has leading whitespace' );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>
</body>
</html>