Make WordPress Core

Changeset 32405


Ignore:
Timestamp:
05/06/2015 08:04:48 PM (11 years ago)
Author:
ocean90
Message:

WPDB: When sanity checking query character sets, there's no need to check queries that don't return user data.

Merges [32374] to the 3.9 branch.

props pento.
see #32104.

Location:
branches/3.9
Files:
2 edited

Legend:

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

    r32398 r32405  
    24662466                // We don't need to check the collation for queries that don't read data.
    24672467                $query = ltrim( $query, "\r\n\t (" );
    2468                 if ( preg_match( '/^(?:SHOW|DESCRIBE|DESC|EXPLAIN)\s/i', $query ) ) {
     2468                if ( preg_match( '/^(?:SHOW|DESCRIBE|DESC|EXPLAIN|CREATE)\s/i', $query ) ) {
    24692469                        return true;
    24702470                }
    … …  
    26772677         */
    26782678        protected function strip_invalid_text_from_query( $query ) {
     2679                // We don't need to check the collation for queries that don't read data.
     2680                $trimmed_query = ltrim( $query, "\r\n\t (" );
     2681                if ( preg_match( '/^(?:SHOW|DESCRIBE|DESC|EXPLAIN|CREATE)\s/i', $trimmed_query ) ) {
     2682                        return $query;
     2683                }
     2684
    26792685                $table = $this->get_table_from_query( $query );
    26802686                if ( $table ) {
  • branches/3.9/tests/phpunit/tests/db/charset.php

    r32389 r32405  
    640640
    641641        /**
     642         * @ticket 32104
     643         */
     644        function data_dont_strip_text_from_schema_queries() {
     645                // An obviously invalid and fake table name.
     646                $table_name = "\xff\xff\xff\xff";
     647
     648                $queries = array(
     649                        "SHOW CREATE TABLE $table_name",
     650                        "DESCRIBE $table_name",
     651                        "DESC $table_name",
     652                        "EXPLAIN SELECT * FROM $table_name",
     653                        "CREATE $table_name( a VARCHAR(100))",
     654                );
     655
     656                foreach ( $queries as &$query ) {
     657                        $query = array( $query );
     658                }
     659                unset( $query );
     660
     661                return $queries;
     662        }
     663
     664        /**
     665         * @dataProvider data_dont_strip_text_from_schema_queries
     666         * @ticket 32104
     667         */
     668        function test_dont_strip_text_from_schema_queries( $query ) {
     669                $return = self::$_wpdb->strip_invalid_text_from_query( $query );
     670                $this->assertEquals( $query, $return );
     671        }
     672
     673        /**
    642674         * @ticket 21212
    643675         */
Note: See TracChangeset for help on using the changeset viewer.