Make WordPress Core


Ignore:
Timestamp:
04/21/2015 07:05:24 AM (11 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.7 branch.

See #32029.

File:
1 edited

Legend:

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

    r32188 r32241  
    19511951            return true;
    19521952        }
     1953
     1954        // We don't need to check the collation for queries that don't read data.
     1955        $query = ltrim( $query, "\r\n\t (" );
     1956        if ( preg_match( '/^(?:SHOW|DESCRIBE|DESC|EXPLAIN)\s/i', $query ) ) {
     1957            return true;
     1958        }
     1959
     1960        // All-ASCII queries don't need extra checking.
     1961        if ( $this->check_ascii( $query ) ) {
     1962            return true;
     1963        }
     1964
    19531965        $table = $this->get_table_from_query( $query );
    19541966        if ( ! $table ) {
     
    19571969
    19581970        $this->checking_collation = true;
    1959         $this->get_table_charset( $table );
     1971        $collation = $this->get_table_charset( $table );
    19601972        $this->checking_collation = false;
     1973
     1974        // Tables with no collation, or latin1 only, don't need extra checking.
     1975        if ( false === $collation || 'latin1' === $collation ) {
     1976            return true;
     1977        }
    19611978
    19621979        $table = strtolower( $table );
     
    19651982        }
    19661983
     1984        // If any of the columns don't have one of these collations, it needs more sanity checking.
    19671985        foreach( $this->col_meta[ $table ] as $col ) {
    19681986            if ( empty( $col->Collation ) ) {
     
    19922010     *                        remove invalid characters, a {@see WP_Error} object is returned.
    19932011     */
     2012        // If any of the columns don't have one of these collations, it needs more sanity checking.
    19942013    protected function strip_invalid_text( $data ) {
    19952014        // Some multibyte character sets that we can check in PHP.
Note: See TracChangeset for help on using the changeset viewer.