Make WordPress Core


Ignore:
Timestamp:
03/02/2024 01:36:02 PM (3 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/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                // Beginning of the string is on a new line to prevent leading whitespace. See https://core.trac.wordpress.org/ticket/56841.
     968                $this->request =
     969                        "{$this->sql_clauses['select']}
     970                         {$this->sql_clauses['from']}
     971                         {$where}
     972                         {$this->sql_clauses['groupby']}
     973                         {$this->sql_clauses['orderby']}
     974                         {$this->sql_clauses['limits']}";
    975975
    976976                if ( $this->query_vars['count'] ) {
Note: See TracChangeset for help on using the changeset viewer.