Make WordPress Core


Ignore:
Timestamp:
04/21/2015 05:43:33 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 4.1 branch.

See #32029.

File:
1 edited

Legend:

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

    r32223 r32234  
    23732373            return true;
    23742374        }
     2375
     2376        // We don't need to check the collation for queries that don't read data.
     2377        $query = ltrim( $query, "\r\n\t (" );
     2378        if ( preg_match( '/^(?:SHOW|DESCRIBE|DESC|EXPLAIN)\s/i', $query ) ) {
     2379            return true;
     2380        }
     2381
     2382        // All-ASCII queries don't need extra checking.
     2383        if ( $this->check_ascii( $query ) ) {
     2384            return true;
     2385        }
     2386
    23752387        $table = $this->get_table_from_query( $query );
    23762388        if ( ! $table ) {
     
    23792391
    23802392        $this->checking_collation = true;
    2381         $this->get_table_charset( $table );
     2393        $collation = $this->get_table_charset( $table );
    23822394        $this->checking_collation = false;
     2395
     2396        // Tables with no collation, or latin1 only, don't need extra checking.
     2397        if ( false === $collation || 'latin1' === $collation ) {
     2398            return true;
     2399        }
    23832400
    23842401        $table = strtolower( $table );
     
    23872404        }
    23882405
     2406        // If any of the columns don't have one of these collations, it needs more sanity checking.
    23892407        foreach( $this->col_meta[ $table ] as $col ) {
    23902408            if ( empty( $col->Collation ) ) {
     
    24142432     *                        remove invalid characters, a {@see WP_Error} object is returned.
    24152433     */
     2434        // If any of the columns don't have one of these collations, it needs more sanity checking.
    24162435    protected function strip_invalid_text( $data ) {
    24172436        // Some multibyte character sets that we can check in PHP.
Note: See TracChangeset for help on using the changeset viewer.