WordPress.org

Make WordPress Core

Changeset 33993


Ignore:
Timestamp:
09/10/2015 06:59:54 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.1 branch.

Props dustinbolton, pento.

See #33470.

Location:
branches/4.1
Files:
2 edited

Legend:

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

    r33480 r33993  
    28152815                . '|UPDATE(?:\s+LOW_PRIORITY)?(?:\s+IGNORE)?'
    28162816                . '|DELETE(?:\s+LOW_PRIORITY|\s+QUICK|\s+IGNORE)*(?:\s+FROM)?'
    2817                 . ')\s+((?:[0-9a-zA-Z$_.`]|[\xC2-\xDF][\x80-\xBF])+)/is', $query, $maybe ) ) {
     2817                . ')\s+((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)/is', $query, $maybe ) ) {
    28182818            return str_replace( '`', '', $maybe[1] );
    28192819        }
     
    28232823                . 'SHOW\s+TABLE\s+STATUS.+(?:LIKE\s+|WHERE\s+Name\s*=\s*)'
    28242824                . '|SHOW\s+(?:FULL\s+)?TABLES.+(?:LIKE\s+|WHERE\s+Name\s*=\s*)'
    2825                 . ')\W((?:[0-9a-zA-Z$_.`]|[\xC2-\xDF][\x80-\xBF])+)\W/is', $query, $maybe ) ) {
     2825                . ')\W((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)\W/is', $query, $maybe ) ) {
    28262826            return str_replace( '`', '', $maybe[1] );
    28272827        }
     
    28422842                . '|(?:GRANT|REVOKE).*ON\s+TABLE'
    28432843                . '|SHOW\s+(?:.*FROM|.*TABLE)'
    2844                 . ')\s+\(*\s*((?:[0-9a-zA-Z$_.`]|[\xC2-\xDF][\x80-\xBF])+)\s*\)*/is', $query, $maybe ) ) {
     2844                . ')\s+\(*\s*((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)\s*\)*/is', $query, $maybe ) ) {
    28452845            return str_replace( '`', '', $maybe[1] );
    28462846        }
  • branches/4.1/tests/phpunit/tests/db.php

    r32412 r33993  
    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(
     
    632636        $querycount = count( $queries );
    633637        for ( $ii = 0; $ii < $querycount; $ii++ ) {
    634             $db_query = str_replace( $table, $db_table, $queries[ $ii ] );
    635             $expected_db_table = str_replace( '`', '', $db_table );
     638            foreach ( $more_tables as $name => $expected_name ) {
     639                $new_query = str_replace( $table, $name, $queries[ $ii ] );
     640                $queries[] = array( $new_query, $expected_name );
     641            }
    636642
    637643            $queries[ $ii ] = array( $queries[ $ii ], $table );
    638             $queries[] = array( $db_query, $expected_db_table );
    639644        }
    640645        return $queries;
Note: See TracChangeset for help on using the changeset viewer.