WordPress.org

Make WordPress Core

Changeset 33997


Ignore:
Timestamp:
09/10/2015 07:19:11 AM (6 years ago)
Author:
pento
Message:

WPDB: get_table_from_query() didn't find table names with hyphens in them.

Merge of [33718] to the 3.8 branch.

Props dustinbolton, pento.

See #33470.

Location:
branches/3.7
Files:
2 edited

Legend:

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

    r32416 r33997  
    24012401                . '|UPDATE(?:\s+LOW_PRIORITY)?(?:\s+IGNORE)?'
    24022402                . '|DELETE(?:\s+LOW_PRIORITY|\s+QUICK|\s+IGNORE)*(?:\s+FROM)?'
    2403                 . ')\s+((?:[0-9a-zA-Z$_.`]|[\xC2-\xDF][\x80-\xBF])+)/is', $query, $maybe ) ) {
     2403                . ')\s+((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)/is', $query, $maybe ) ) {
    24042404            return str_replace( '`', '', $maybe[1] );
    24052405        }
     
    24092409                . 'SHOW\s+TABLE\s+STATUS.+(?:LIKE\s+|WHERE\s+Name\s*=\s*)'
    24102410                . '|SHOW\s+(?:FULL\s+)?TABLES.+(?:LIKE\s+|WHERE\s+Name\s*=\s*)'
    2411                 . ')\W((?:[0-9a-zA-Z$_.`]|[\xC2-\xDF][\x80-\xBF])+)\W/is', $query, $maybe ) ) {
     2411                . ')\W((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)\W/is', $query, $maybe ) ) {
    24122412            return str_replace( '`', '', $maybe[1] );
    24132413        }
     
    24282428                . '|(?:GRANT|REVOKE).*ON\s+TABLE'
    24292429                . '|SHOW\s+(?:.*FROM|.*TABLE)'
    2430                 . ')\s+\(*\s*((?:[0-9a-zA-Z$_.`]|[\xC2-\xDF][\x80-\xBF])+)\s*\)*/is', $query, $maybe ) ) {
     2430                . ')\s+\(*\s*((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)\s*\)*/is', $query, $maybe ) ) {
    24312431            return str_replace( '`', '', $maybe[1] );
    24322432        }
  • branches/3.7/tests/phpunit/tests/db.php

    r32416 r33997  
    291291    function data_get_table_from_query() {
    292292        $table = 'a_test_table_name';
    293         $db_table = '`a_test_db`.`another_test_table`';
     293        $more_tables = array(
     294            // table_name => expected_value
     295            '`a_test_db`.`another_test_table`' => 'a_test_db.another_test_table',
     296            'a-test-with-dashes'               => 'a-test-with-dashes',
     297        );
    294298
    295299        $queries = array(
     
    396400        $querycount = count( $queries );
    397401        for ( $ii = 0; $ii < $querycount; $ii++ ) {
    398             $db_query = str_replace( $table, $db_table, $queries[ $ii ] );
    399             $expected_db_table = str_replace( '`', '', $db_table );
     402            foreach ( $more_tables as $name => $expected_name ) {
     403                $new_query = str_replace( $table, $name, $queries[ $ii ] );
     404                $queries[] = array( $new_query, $expected_name );
     405            }
    400406
    401407            $queries[ $ii ] = array( $queries[ $ii ], $table );
    402             $queries[] = array( $db_query, $expected_db_table );
    403408        }
    404409        return $queries;
Note: See TracChangeset for help on using the changeset viewer.