Make WordPress Core

Changeset 60782


Ignore:
Timestamp:
09/19/2025 11:58:02 AM (11 months ago)
Author:
SergeyBiryukov
Message:

Database: Do not report an extra update in dbDelta() with backticks in table name.

Follow-up to [10948], [20704].

Props leewillis77, swissspidy, johnbillion, SergeyBiryukov.
Fixes #63976.

Location:
trunk
Files:
2 edited

Legend:

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

    r60725 r60782  
    29632963        foreach ( $queries as $qry ) {
    29642964                if ( preg_match( '|CREATE TABLE ([^ ]*)|', $qry, $matches ) ) {
    2965                         $cqueries[ trim( $matches[1], '`' ) ] = $qry;
    2966                         $for_update[ $matches[1] ]            = 'Created table ' . $matches[1];
     2965                        $table_name = trim( $matches[1], '`' );
     2966
     2967                        $cqueries[ $table_name ]   = $qry;
     2968                        $for_update[ $table_name ] = 'Created table ' . $matches[1];
    29672969                        continue;
    29682970                }
  • trunk/tests/phpunit/tests/db/dbDelta.php

    r57987 r60782  
    142142
    143143        /**
    144          * Test that it does nothing for an existing table.
     144         * Test that no update is reported for an existing table.
    145145         */
    146146        public function test_existing_table() {
     
    157157                                KEY compound_key (id,column_1($this->max_index_length))
    158158                        )
    159                         "
     159                        ",
     160                        false
     161                );
     162
     163                $this->assertSame( array(), $updates );
     164        }
     165
     166        /**
     167         * Test that no update is reported for an existing table name in backticks.
     168         *
     169         * @ticket 63976
     170         */
     171        public function test_existing_table_name_in_backticks() {
     172
     173                global $wpdb;
     174
     175                $updates = dbDelta(
     176                        "
     177                        CREATE TABLE `{$wpdb->prefix}dbdelta_test` (
     178                                id bigint(20) NOT NULL AUTO_INCREMENT,
     179                                column_1 varchar(255) NOT NULL,
     180                                PRIMARY KEY  (id),
     181                                KEY key_1 (column_1($this->max_index_length)),
     182                                KEY compound_key (id,column_1($this->max_index_length))
     183                        )
     184                        ",
     185                        false
    160186                );
    161187
Note: See TracChangeset for help on using the changeset viewer.