WordPress.org

Make WordPress Core

Changeset 32232


Ignore:
Timestamp:
04/21/2015 05:10:11 AM (5 years ago)
Author:
pento
Message:

WPDB: When deciding if a query needs extra sanity checking based on collation, we can quickly return if it's a query that will never return user data.

Fixes #32029.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/wp-db.php

    r32162 r32232  
    24002400        }
    24012401
     2402        // We don't need to check the collation for queries that don't read data.
     2403        $query = ltrim( $query, "\r\n\t (" );
     2404        if ( preg_match( '/^(?:SHOW|DESCRIBE|DESC|EXPLAIN)\s/i', $query ) ) {
     2405            return true;
     2406        }
     2407
    24022408        $table = $this->get_table_from_query( $query );
    24032409        if ( ! $table ) {
     
    24062412
    24072413        $this->checking_collation = true;
    2408         $this->get_table_charset( $table );
     2414        $collation = $this->get_table_charset( $table );
    24092415        $this->checking_collation = false;
     2416
     2417        // Tables with no collation, or latin1 only, don't need extra checking.
     2418        if ( false === $collation || 'latin1' === $collation ) {
     2419            return true;
     2420        }
    24102421
    24112422        $table = strtolower( $table );
     
    24142425        }
    24152426
     2427        // If any of the columns don't have one of these collations, it needs more sanity checking.
    24162428        foreach( $this->col_meta[ $table ] as $col ) {
    24172429            if ( empty( $col->Collation ) ) {
  • trunk/tests/phpunit/tests/db/charset.php

    r32162 r32232  
    506506            $value[2] = "SELECT * FROM $this_table_name";
    507507            $value[3] = "DROP TABLE IF EXISTS $this_table_name";
     508            $value[4] = array(
     509                "SHOW FULL TABLES LIKE $this_table_name",
     510                "DESCRIBE $this_table_name",
     511                "DESC $this_table_name",
     512                "EXPLAIN SELECT * FROM $this_table_name",
     513            );
    508514        }
    509515        unset( $value );
     
    517523     * @ticket 21212
    518524     */
    519     function test_table_collation_check( $create, $expected, $query, $drop ) {
     525    function test_table_collation_check( $create, $expected, $query, $drop, $always_true ) {
    520526        self::$_wpdb->query( $drop );
    521527
     
    525531        $this->assertEquals( $expected, $return );
    526532
     533        foreach( $always_true as $true_query ) {
     534            $return = self::$_wpdb->check_safe_collation( $true_query );
     535            $this->assertTrue( $return );
     536        }
     537
    527538        self::$_wpdb->query( $drop );
    528539    }
Note: See TracChangeset for help on using the changeset viewer.