Make WordPress Core


Ignore:
Timestamp:
04/21/2015 07:00:52 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.8 branch.

See #32029.

File:
1 edited

Legend:

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

    r32186 r32240  
    19591959            return true;
    19601960        }
     1961
     1962        // We don't need to check the collation for queries that don't read data.
     1963        $query = ltrim( $query, "\r\n\t (" );
     1964        if ( preg_match( '/^(?:SHOW|DESCRIBE|DESC|EXPLAIN)\s/i', $query ) ) {
     1965            return true;
     1966        }
     1967
     1968        // All-ASCII queries don't need extra checking.
     1969        if ( $this->check_ascii( $query ) ) {
     1970            return true;
     1971        }
     1972
    19611973        $table = $this->get_table_from_query( $query );
    19621974        if ( ! $table ) {
     
    19651977
    19661978        $this->checking_collation = true;
    1967         $this->get_table_charset( $table );
     1979        $collation = $this->get_table_charset( $table );
    19681980        $this->checking_collation = false;
     1981
     1982        // Tables with no collation, or latin1 only, don't need extra checking.
     1983        if ( false === $collation || 'latin1' === $collation ) {
     1984            return true;
     1985        }
    19691986
    19701987        $table = strtolower( $table );
     
    19731990        }
    19741991
     1992        // If any of the columns don't have one of these collations, it needs more sanity checking.
    19751993        foreach( $this->col_meta[ $table ] as $col ) {
    19761994            if ( empty( $col->Collation ) ) {
     
    20002018     *                        remove invalid characters, a {@see WP_Error} object is returned.
    20012019     */
     2020        // If any of the columns don't have one of these collations, it needs more sanity checking.
    20022021    protected function strip_invalid_text( $data ) {
    20032022        // Some multibyte character sets that we can check in PHP.
Note: See TracChangeset for help on using the changeset viewer.