Make WordPress Core


Ignore:
Timestamp:
08/22/2022 03:37:59 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Database: Account for utf8 being renamed to utf8mb3 in newer MariaDB and MySQL versions.

From MariaDB 10.6.1 release notes:

The utf8 character set (and related collations) is now by default an alias for utf8mb3 rather than the other way around. It can be set to imply utf8mb4 by changing the value of the old_mode system variable (MDEV-8334).

From MySQL 8.0.30 release notes:

Important Change: A previous change renamed character sets having deprecated names prefixed with utf8_ to use utf8mb3_ instead. In this release, we rename the utf8_ collations as well, using the utf8mb3_ prefix; this is to make the collation names consistent with those of the character sets, not to rely any longer on the deprecated collation names, and to clarify the distinction between utf8mb3 and utf8mb4. The names using the utf8mb3_ prefix are now used exclusively for these collations in the output of SHOW statements such as SHOW CREATE TABLE, as well as in the values displayed in the columns of Information Schema tables including the COLLATIONS and COLUMNS tables.

This commit adds utf8mb3_bin and utf8mb3_general_ci to the list of safe collations recognized by wpdb::check_safe_collation(). The full list is now as follows:

  • utf8_bin
  • utf8_general_ci
  • utf8mb3_bin
  • utf8mb3_general_ci
  • utf8mb4_bin
  • utf8mb4_general_ci

The change is covered by existing database charset unit tests: six tests which previously failed on MariaDB 10.6.1+ or MySQL 8.0.30+ now pass.

Includes:

  • Adjusting the expected test results based on MariaDB and MySQL version.
  • Using named data providers for the affected tests to make test output more descriptive.
  • Adding a failure message to each assertion when multiple assertions are used in the test.

References:

Follow-up to [30345], [32162], [37320].

Props skithund, ayeshrajans, JavierCasares, SergeyBiryukov.
Fixes #53623.

File:
1 edited

Legend:

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

    r53749 r53918  
    33773377
    33783378        // If any of the columns don't have one of these collations, it needs more sanity checking.
     3379        $safe_collations = array(
     3380            'utf8_bin',
     3381            'utf8_general_ci',
     3382            'utf8mb3_bin',
     3383            'utf8mb3_general_ci',
     3384            'utf8mb4_bin',
     3385            'utf8mb4_general_ci',
     3386        );
     3387
    33793388        foreach ( $this->col_meta[ $table ] as $col ) {
    33803389            if ( empty( $col->Collation ) ) {
     
    33823391            }
    33833392
    3384             if ( ! in_array( $col->Collation, array( 'utf8_general_ci', 'utf8_bin', 'utf8mb4_general_ci', 'utf8mb4_bin' ), true ) ) {
     3393            if ( ! in_array( $col->Collation, $safe_collations, true ) ) {
    33853394                return false;
    33863395            }
Note: See TracChangeset for help on using the changeset viewer.