Make WordPress Core


Ignore:
Timestamp:
10/31/2017 11:59:43 AM (7 years ago)
Author:
pento
Message:

Database: Restore numbered placeholders in wpdb::prepare().

[41496] removed support for numbered placeholders in queries send through wpdb::prepare(), which, despite being undocumented, were quite commonly used.

This change restores support for numbered placeholders (as well as a subset of placeholder formatting), while also adding extra checks to ensure the correct number of arguments are being passed to wpdb::prepare(), given the number of placeholders.

See #41925.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/date/query.php

    r35242 r42056  
    513513     */
    514514    public function test_build_time_query_should_not_discard_hour_0() {
     515        global $wpdb;
    515516        $q = new WP_Date_Query( array() );
    516517
    517518        $found = $q->build_time_query( 'post_date', '=', 0, 10 );
    518519
    519         $this->assertContains( '%H', $found );
     520        $this->assertContains( '%H', $wpdb->remove_placeholder_escape( $found ) );
    520521    }
    521522
     
    613614
    614615    public function test_build_time_query_hour_minute() {
     616        global $wpdb;
    615617        $q = new WP_Date_Query( array() );
    616618
     
    619621        // $compare value is floating point - use regex to account for
    620622        // varying precision on different PHP installations
    621         $this->assertRegExp( "/DATE_FORMAT\( post_date, '%H\.%i' \) = 5\.150*/", $found );
     623        $this->assertRegExp( "/DATE_FORMAT\( post_date, '%H\.%i' \) = 5\.150*/", $wpdb->remove_placeholder_escape( $found ) );
    622624    }
    623625
    624626    public function test_build_time_query_hour_minute_second() {
     627        global $wpdb;
    625628        $q = new WP_Date_Query( array() );
    626629
     
    629632        // $compare value is floating point - use regex to account for
    630633        // varying precision on different PHP installations
    631         $this->assertRegExp( "/DATE_FORMAT\( post_date, '%H\.%i%s' \) = 5\.15350*/", $found );
     634        $this->assertRegExp( "/DATE_FORMAT\( post_date, '%H\.%i%s' \) = 5\.15350*/", $wpdb->remove_placeholder_escape( $found ) );
    632635    }
    633636
    634637    public function test_build_time_query_minute_second() {
     638        global $wpdb;
    635639        $q = new WP_Date_Query( array() );
    636640
     
    639643        // $compare value is floating point - use regex to account for
    640644        // varying precision on different PHP installations
    641         $this->assertRegExp( "/DATE_FORMAT\( post_date, '0\.%i%s' \) = 0\.15350*/", $found );
     645        $this->assertRegExp( "/DATE_FORMAT\( post_date, '0\.%i%s' \) = 0\.15350*/", $wpdb->remove_placeholder_escape( $found ) );
    642646    }
    643647
Note: See TracChangeset for help on using the changeset viewer.