Make WordPress Core


Ignore:
Timestamp:
03/02/2024 01:36:02 PM (13 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/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        // Beginning of the string is on a new line to prevent leading whitespace. See https://core.trac.wordpress.org/ticket/56841.
     485        $this->request =
     486            "{$this->sql_clauses['select']}
     487             {$this->sql_clauses['from']}
     488             {$where}
     489             {$this->sql_clauses['groupby']}
     490             {$this->sql_clauses['orderby']}
     491             {$this->sql_clauses['limits']}";
    492492
    493493        if ( $this->query_vars['count'] ) {
Note: See TracChangeset for help on using the changeset viewer.