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/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                // Beginning of the string is on a new line to prevent leading whitespace. See https://core.trac.wordpress.org/ticket/56841.
     699                $this->request =
     700                        "{$this->sql_clauses['select']}
     701                         {$this->sql_clauses['from']}
     702                         {$where}
     703                         {$this->sql_clauses['groupby']}
     704                         {$this->sql_clauses['orderby']}
     705                         {$this->sql_clauses['limits']}";
    706706
    707707                if ( $this->query_vars['count'] ) {
Note: See TracChangeset for help on using the changeset viewer.