Make WordPress Core


Ignore:
Timestamp:
03/02/2024 01:36:02 PM (2 years 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/comment/query.php

    r57653 r57750  
    53515351        $this->assertStringNotContainsString( ' comment_ID ', $wpdb->last_query );
    53525352    }
     5353
     5354    /**
     5355     * @ticket 56841
     5356     */
     5357    public function test_query_does_not_have_leading_whitespace() {
     5358        self::factory()->comment->create(
     5359            array(
     5360                'comment_post_ID' => self::$post_id,
     5361                'user_id'         => 7,
     5362            )
     5363        );
     5364
     5365        $q = new WP_Comment_Query();
     5366        $q->query(
     5367            array(
     5368                'count'   => true,
     5369                'orderby' => 'none',
     5370            )
     5371        );
     5372
     5373        $this->assertSame( ltrim( $q->request ), $q->request, 'The query has leading whitespace' );
     5374    }
    53535375}
Note: See TracChangeset for help on using the changeset viewer.