WordPress.org

Make WordPress Core

Changeset 33994


Ignore:
Timestamp:
09/10/2015 07:04:04 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 4.0 branch.

Props dustinbolton, pento.

See #33470.

Location:
branches/4.0
Files:
2 edited

Legend:

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

    r32413 r33994  
    28222822                . '|UPDATE(?:\s+LOW_PRIORITY)?(?:\s+IGNORE)?'
    28232823                . '|DELETE(?:\s+LOW_PRIORITY|\s+QUICK|\s+IGNORE)*(?:\s+FROM)?'
    2824                 . ')\s+((?:[0-9a-zA-Z$_.`]|[\xC2-\xDF][\x80-\xBF])+)/is', $query, $maybe ) ) {
     2824                . ')\s+((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)/is', $query, $maybe ) ) {
    28252825            return str_replace( '`', '', $maybe[1] );
    28262826        }
     
    28302830                . 'SHOW\s+TABLE\s+STATUS.+(?:LIKE\s+|WHERE\s+Name\s*=\s*)'
    28312831                . '|SHOW\s+(?:FULL\s+)?TABLES.+(?:LIKE\s+|WHERE\s+Name\s*=\s*)'
    2832                 . ')\W((?:[0-9a-zA-Z$_.`]|[\xC2-\xDF][\x80-\xBF])+)\W/is', $query, $maybe ) ) {
     2832                . ')\W((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)\W/is', $query, $maybe ) ) {
    28332833            return str_replace( '`', '', $maybe[1] );
    28342834        }
     
    28492849                . '|(?:GRANT|REVOKE).*ON\s+TABLE'
    28502850                . '|SHOW\s+(?:.*FROM|.*TABLE)'
    2851                 . ')\s+\(*\s*((?:[0-9a-zA-Z$_.`]|[\xC2-\xDF][\x80-\xBF])+)\s*\)*/is', $query, $maybe ) ) {
     2851                . ')\s+\(*\s*((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)\s*\)*/is', $query, $maybe ) ) {
    28522852            return str_replace( '`', '', $maybe[1] );
    28532853        }
  • branches/4.0/tests/phpunit/tests/db.php

    r32413 r33994  
    492492    function data_get_table_from_query() {
    493493        $table = 'a_test_table_name';
    494         $db_table = '`a_test_db`.`another_test_table`';
     494        $more_tables = array(
     495            // table_name => expected_value
     496            '`a_test_db`.`another_test_table`' => 'a_test_db.another_test_table',
     497            'a-test-with-dashes'               => 'a-test-with-dashes',
     498        );
    495499
    496500        $queries = array(
     
    597601        $querycount = count( $queries );
    598602        for ( $ii = 0; $ii < $querycount; $ii++ ) {
    599             $db_query = str_replace( $table, $db_table, $queries[ $ii ] );
    600             $expected_db_table = str_replace( '`', '', $db_table );
     603            foreach ( $more_tables as $name => $expected_name ) {
     604                $new_query = str_replace( $table, $name, $queries[ $ii ] );
     605                $queries[] = array( $new_query, $expected_name );
     606            }
    601607
    602608            $queries[ $ii ] = array( $queries[ $ii ], $table );
    603             $queries[] = array( $db_query, $expected_db_table );
    604609        }
    605610        return $queries;
Note: See TracChangeset for help on using the changeset viewer.