WordPress.org

Make WordPress Core

Changeset 33718


Ignore:
Timestamp:
08/24/2015 12:18:49 AM (6 years ago)
Author:
pento
Message:

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

Props dustinbolton for the fix.

Fixes #33470.

Location:
trunk
Files:
2 edited

Legend:

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

    r33701 r33718  
    28712871                . '|UPDATE(?:\s+LOW_PRIORITY)?(?:\s+IGNORE)?'
    28722872                . '|DELETE(?:\s+LOW_PRIORITY|\s+QUICK|\s+IGNORE)*(?:\s+FROM)?'
    2873                 . ')\s+((?:[0-9a-zA-Z$_.`]|[\xC2-\xDF][\x80-\xBF])+)/is', $query, $maybe ) ) {
     2873                . ')\s+((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)/is', $query, $maybe ) ) {
    28742874            return str_replace( '`', '', $maybe[1] );
    28752875        }
     
    28792879                . 'SHOW\s+TABLE\s+STATUS.+(?:LIKE\s+|WHERE\s+Name\s*=\s*)'
    28802880                . '|SHOW\s+(?:FULL\s+)?TABLES.+(?:LIKE\s+|WHERE\s+Name\s*=\s*)'
    2881                 . ')\W((?:[0-9a-zA-Z$_.`]|[\xC2-\xDF][\x80-\xBF])+)\W/is', $query, $maybe ) ) {
     2881                . ')\W((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)\W/is', $query, $maybe ) ) {
    28822882            return str_replace( '`', '', $maybe[1] );
    28832883        }
     
    28982898                . '|(?:GRANT|REVOKE).*ON\s+TABLE'
    28992899                . '|SHOW\s+(?:.*FROM|.*TABLE)'
    2900                 . ')\s+\(*\s*((?:[0-9a-zA-Z$_.`]|[\xC2-\xDF][\x80-\xBF])+)\s*\)*/is', $query, $maybe ) ) {
     2900                . ')\s+\(*\s*((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)\s*\)*/is', $query, $maybe ) ) {
    29012901            return str_replace( '`', '', $maybe[1] );
    29022902        }
  • trunk/tests/phpunit/tests/db.php

    r33259 r33718  
    527527    function data_get_table_from_query() {
    528528        $table = 'a_test_table_name';
    529         $db_table = '`a_test_db`.`another_test_table`';
     529        $more_tables = array(
     530            // table_name => expected_value
     531            '`a_test_db`.`another_test_table`' => 'a_test_db.another_test_table',
     532            'a-test-with-dashes'               => 'a-test-with-dashes',
     533        );
    530534
    531535        $queries = array(
     
    637641        $querycount = count( $queries );
    638642        for ( $ii = 0; $ii < $querycount; $ii++ ) {
    639             $db_query = str_replace( $table, $db_table, $queries[ $ii ] );
    640             $expected_db_table = str_replace( '`', '', $db_table );
     643            foreach ( $more_tables as $name => $expected_name ) {
     644                $new_query = str_replace( $table, $name, $queries[ $ii ] );
     645                $queries[] = array( $new_query, $expected_name );
     646            }
    641647
    642648            $queries[ $ii ] = array( $queries[ $ii ], $table );
    643             $queries[] = array( $db_query, $expected_db_table );
    644649        }
    645650        return $queries;
Note: See TracChangeset for help on using the changeset viewer.