Make WordPress Core


Ignore:
Timestamp:
04/21/2015 06:57:58 AM (10 years ago)
Author:
pento
Message:

WPDB: When deciding if a query needs extra sanity checking based on collation, return early when we can. Merges [32232] and [32233] to the 3.9 branch.

See #32029.

File:
1 edited

Legend:

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

    r32224 r32239  
    23362336            return true;
    23372337        }
     2338
     2339        // We don't need to check the collation for queries that don't read data.
     2340        $query = ltrim( $query, "\r\n\t (" );
     2341        if ( preg_match( '/^(?:SHOW|DESCRIBE|DESC|EXPLAIN)\s/i', $query ) ) {
     2342            return true;
     2343        }
     2344
     2345        // All-ASCII queries don't need extra checking.
     2346        if ( $this->check_ascii( $query ) ) {
     2347            return true;
     2348        }
     2349
    23382350        $table = $this->get_table_from_query( $query );
    23392351        if ( ! $table ) {
     
    23422354
    23432355        $this->checking_collation = true;
    2344         $this->get_table_charset( $table );
     2356        $collation = $this->get_table_charset( $table );
    23452357        $this->checking_collation = false;
     2358
     2359        // Tables with no collation, or latin1 only, don't need extra checking.
     2360        if ( false === $collation || 'latin1' === $collation ) {
     2361            return true;
     2362        }
    23462363
    23472364        $table = strtolower( $table );
     
    23502367        }
    23512368
     2369        // If any of the columns don't have one of these collations, it needs more sanity checking.
    23522370        foreach( $this->col_meta[ $table ] as $col ) {
    23532371            if ( empty( $col->Collation ) ) {
     
    23772395     *                        remove invalid characters, a {@see WP_Error} object is returned.
    23782396     */
     2397        // If any of the columns don't have one of these collations, it needs more sanity checking.
    23792398    protected function strip_invalid_text( $data ) {
    23802399        // Some multibyte character sets that we can check in PHP.
Note: See TracChangeset for help on using the changeset viewer.