Make WordPress Core

Changeset 57750

Timestamp:
03/02/2024 01:36:02 PM (5 months ago)
Author:
swissspidy
Message:

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 #56841.

Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-comment-query.php

    r57719 r57750  
    965965        $this->sql_clauses['limits']  = $limits;
    966966
    967         $this->request = "
    968             {$this->sql_clauses['select']}
    969             {$this->sql_clauses['from']}
    970             {$where}
    971             {$this->sql_clauses['groupby']}
    972             {$this->sql_clauses['orderby']}
    973             {$this->sql_clauses['limits']}
    974         ";
     967       
     968       
     969            ']}
     970            }
     971            }
     972            by']}
     973            ']}
     974        ";
    975975
    976976        if ( $this->query_vars['count'] ) {
  • trunk/src/wp-includes/class-wp-network-query.php

    r57719 r57750  
    482482        $this->sql_clauses['limits']  = $limits;
    483483
    484         $this->request = "
    485             {$this->sql_clauses['select']}
    486             {$this->sql_clauses['from']}
    487             {$where}
    488             {$this->sql_clauses['groupby']}
    489             {$this->sql_clauses['orderby']}
    490             {$this->sql_clauses['limits']}
    491         ";
     484       
     485       
     486            ']}
     487            }
     488            }
     489            by']}
     490            ']}
     491        ";
    492492
    493493        if ( $this->query_vars['count'] ) {
  • trunk/src/wp-includes/class-wp-query.php

    r57648 r57750  
    31053105        }
    31063106
    3107         $old_request = "
    3108             SELECT $found_rows $distinct $fields
    3109             FROM {$wpdb->posts} $join
    3110             WHERE 1=1 $where
    3111             $groupby
    3112             $orderby
    3113             $limits
    3114         ";
     3107       
     3108       
     3109           
     3110           
     3111           
     3112            by
     3113           
     3114        ";
    31153115
    31163116        $this->request = $old_request;
     
    33083308                // First get the IDs and then fill in the objects.
    33093309
    3310                 $this->request = "
    3311                     SELECT $found_rows $distinct {$wpdb->posts}.ID
    3312                     FROM {$wpdb->posts} $join
    3313                     WHERE 1=1 $where
    3314                     $groupby
    3315                     $orderby
    3316                     $limits
    3317                 ";
     3310               
     3311               
     3312                   
     3313                   
     3314                   
     3315                    by
     3316                   
     3317                ";
    33183318
    33193319                /**
  • trunk/src/wp-includes/class-wp-site-query.php

    r57648 r57750  
    696696        $this->sql_clauses['limits']  = $limits;
    697697
    698         $this->request = "
    699             {$this->sql_clauses['select']}
    700             {$this->sql_clauses['from']}
    701             {$where}
    702             {$this->sql_clauses['groupby']}
    703             {$this->sql_clauses['orderby']}
    704             {$this->sql_clauses['limits']}
    705         ";
     698       
     699       
     700            ']}
     701            }
     702            }
     703            by']}
     704            ']}
     705        ";
    706706
    707707        if ( $this->query_vars['count'] ) {
  • trunk/src/wp-includes/class-wp-term-query.php

    r57719 r57750  
    753753        $this->sql_clauses['limits']  = $limits;
    754754
    755         $this->request = "
    756             {$this->sql_clauses['select']}
    757             {$this->sql_clauses['from']}
    758             {$where}
    759             {$this->sql_clauses['orderby']}
    760             {$this->sql_clauses['limits']}
    761         ";
     755       
     756       
     757            ']}
     758            }
     759            }
     760            ']}
     761        ";
    762762
    763763        $this->terms = null;
  • trunk/src/wp-includes/class-wp-user-query.php

    r56543 r57750  
    819819
    820820        if ( null === $this->results ) {
    821             $this->request = "
    822                 SELECT {$this->query_fields}
    823                 {$this->query_from}
    824                 {$this->query_where}
    825                 {$this->query_orderby}
    826                 {$this->query_limit}
    827             ";
     821           
     822           
     823                }
     824                }
     825                }
     826                }
     827            ";
    828828            $cache_value   = false;
    829829            $cache_key     = $this->generate_cache_key( $qv, $this->request );
  • trunk/tests/phpunit/tests/comment/query.php

    r57653 r57750  
    53515351        $this->assertStringNotContainsString( ' comment_ID ', $wpdb->last_query );
    53525352    }
     5353
     5354
     5355
     5356
     5357
     5358
     5359
     5360
     5361
     5362
     5363
     5364
     5365
     5366
     5367
     5368
     5369
     5370
     5371
     5372
     5373
     5374
    53535375}
  • trunk/tests/phpunit/tests/multisite/wpNetworkQuery.php

    r55745 r57750  
    609609            return array( get_network( self::$network_ids['wordpress.org/'] ) );
    610610        }
     611
     612
     613
     614
     615
     616
     617
     618
     619
     620
     621
     622
     623
     624
     625
     626
     627
    611628    }
    612629
  • trunk/tests/phpunit/tests/multisite/wpSiteQuery.php

    r55745 r57750  
    11631163            return array( get_site( self::$site_ids['wordpress.org/'] ) );
    11641164        }
     1165
     1166
     1167
     1168
     1169
     1170
     1171
     1172
     1173
     1174
     1175
     1176
     1177
     1178
     1179
     1180
     1181
     1182
     1183
     1184
    11651185    }
    11661186
  • trunk/tests/phpunit/tests/post/query.php

    r57653 r57750  
    793793        $this->assertSame( (bool) wp_using_ext_object_cache(), $filter->get_args()[0][0] );
    794794    }
     795
     796
     797
     798
     799
     800
     801
     802
     803
     804
     805
     806
     807
     808
     809
     810
     811
     812
     813
     814
     815
     816
     817
     818
     819
     820
     821
     822
     823
     824
     825
     826
     827
     828
    795829}
  • trunk/tests/phpunit/tests/term/query.php

    r56555 r57750  
    11241124        );
    11251125    }
     1126
     1127
     1128
     1129
     1130
     1131
     1132
     1133
     1134
     1135
     1136
     1137
     1138
     1139
     1140
    11261141}
  • trunk/tests/phpunit/tests/user/query.php

    r57325 r57750  
    23792379        );
    23802380    }
     2381
     2382
     2383
     2384
     2385
     2386
     2387
     2388
     2389
     2390
     2391
     2392
     2393
    23812394}
Note: See TracChangeset for help on using the changeset viewer.