Make WordPress Core


Ignore:
Timestamp:
03/02/2024 01:36:02 PM (12 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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     * @ticket 56841
     798     */
     799    public function test_query_does_not_have_leading_whitespace() {
     800        add_filter( 'split_the_query', '__return_false' );
     801
     802        $q = new WP_Query(
     803            array(
     804                'posts_per_page' => 501,
     805            )
     806        );
     807
     808        remove_filter( 'split_the_query', '__return_false' );
     809
     810        $this->assertSame( ltrim( $q->request ), $q->request, 'The query has leading whitespace' );
     811    }
     812
     813    /**
     814     * @ticket 56841
     815     */
     816    public function test_query_does_not_have_leading_whitespace_split_the_query() {
     817        add_filter( 'split_the_query', '__return_true' );
     818
     819        $q = new WP_Query(
     820            array(
     821                'posts_per_page' => 501,
     822            )
     823        );
     824
     825        remove_filter( 'split_the_query', '__return_true' );
     826
     827        $this->assertSame( ltrim( $q->request ), $q->request, 'The query has leading whitespace' );
     828    }
    795829}
Note: See TracChangeset for help on using the changeset viewer.