Make WordPress Core

Changeset 32235


Ignore:
Timestamp:
04/21/2015 06:18:58 AM (9 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.0 branch.

See #32029.

File:
1 edited

Legend:

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

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