Make WordPress Core

Changeset 64434


Ignore:
Timestamp:
10/16/2026 10:48:16 PM (28 hours ago)
Author:
SergeyBiryukov
Message:

Database: Correct uppercasing the SQL mode values in wpdb::set_sql_mode().

wpdb::set_sql_mode() aimed to convert lowercased values to uppercase before comparing them with the incompatible_sql_modes filter results, but the case conversion was erroneously performed on numeric keys of the modes array rather than the string values. This commit ensures the array values are converted as expected.

Follow-up to r27072.

Props DavidAnderson, SergeyBiryukov.
Fixes #66326.

Location:
trunk
Files:
2 edited

Legend:

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

    r64305 r64434  
    966966                }
    967967
    968                 $modes = array_change_key_case( $modes, CASE_UPPER );
     968                $modes = array_map( 'strtoupper', $modes );
    969969
    970970                /**
  • trunk/tests/phpunit/tests/db.php

    r64319 r64434  
    294294
    295295        /**
    296          * Test that SQL modes are set correctly
     296         * Test that SQL modes are set correctly.
    297297         *
    298298         * @ticket 26847
    … …  
    309309                $check_new_modes = $wpdb->get_var( 'SELECT @@SESSION.sql_mode;' );
    310310                $this->assertSameSets( $new_modes, explode( ',', $check_new_modes ) );
     311
     312                $wpdb->set_sql_mode( empty( $current_modes ) ? array() : explode( ',', $current_modes ) );
     313        }
     314
     315        /**
     316         * Test that SQL modes are uppercased correctly.
     317         *
     318         * @ticket 66326
     319         */
     320        public function test_set_sql_mode_corrects_lowercase() {
     321                global $wpdb;
     322
     323                $current_modes = $wpdb->get_var( 'SELECT @@SESSION.sql_mode;' );
     324
     325                $new_modes = array( 'ignore_space', 'no_auto_value_on_zero' );
     326
     327                $wpdb->set_sql_mode( $new_modes );
     328
     329                $check_new_modes = $wpdb->get_var( 'SELECT @@SESSION.sql_mode;' );
     330                $this->assertSameSets( array_map( 'strtoupper', $new_modes ), explode( ',', $check_new_modes ) );
    311331
    312332                $wpdb->set_sql_mode( empty( $current_modes ) ? array() : explode( ',', $current_modes ) );
Note: See TracChangeset for help on using the changeset viewer.