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-query.php

    r57648 r57750  
    31053105        }
    31063106
    3107         $old_request = "
    3108             SELECT $found_rows $distinct $fields
    3109             FROM {$wpdb->posts} $join
    3110             WHERE 1=1 $where
    3111             $groupby
    3112             $orderby
    3113             $limits
    3114         ";
     3107        // Beginning of the string is on a new line to prevent leading whitespace. See https://core.trac.wordpress.org/ticket/56841.
     3108        $old_request =
     3109            "SELECT $found_rows $distinct $fields
     3110             FROM {$wpdb->posts} $join
     3111             WHERE 1=1 $where
     3112             $groupby
     3113             $orderby
     3114             $limits";
    31153115
    31163116        $this->request = $old_request;
     
    33083308                // First get the IDs and then fill in the objects.
    33093309
    3310                 $this->request = "
    3311                     SELECT $found_rows $distinct {$wpdb->posts}.ID
    3312                     FROM {$wpdb->posts} $join
    3313                     WHERE 1=1 $where
    3314                     $groupby
    3315                     $orderby
    3316                     $limits
    3317                 ";
     3310                // Beginning of the string is on a new line to prevent leading whitespace. See https://core.trac.wordpress.org/ticket/56841.
     3311                $this->request =
     3312                    "SELECT $found_rows $distinct {$wpdb->posts}.ID
     3313                     FROM {$wpdb->posts} $join
     3314                     WHERE 1=1 $where
     3315                     $groupby
     3316                     $orderby
     3317                     $limits";
    33183318
    33193319                /**
Note: See TracChangeset for help on using the changeset viewer.