Database: Correct MariaDB version check in wpdb::has_cap().

MariaDB version is reported differently between PHP versions:
* PHP 8.0.16 or later: `10.6.8-MariaDB`
* PHP 8.0.15 or earlier: `5.5.5-10.6.8-MariaDB`

The latter includes PHP 7.4.x and PHP 5.6.x as well, where the version is also reported with the `5.5.5-` prefix.

This commit makes an adjustment to `wpdb::has_cap()` to check for the correct MariaDB version.

This resolves an issue where the `utf8mb4_unicode_520_ci` collation, which is available in MariaDB since version 10.2, was previously not detected correctly.

References:
* [https://github.com/php/php-src/issues/7972 php-src: #7972: MariaDB version prefix 5.5.5- is not stripped]
* [https://github.com/php/php-src/pull/7963 php-src: PR #7963 Fix GH-7932: MariaDB version prefix not always stripped]
* [https://mariadb.com/docs/reference/mdb/collations/utf8mb4_unicode_520_ci/ MariaDB Documentation: utf8mb4_unicode_520_ci]

Follow-up to [37523], [53919].

Props jamieburchell, SergeyBiryukov.
Fixes #54841.

git-svn-id: https://develop.svn.wordpress.org/trunk@54384 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2022-10-04 15:39:28 +00:00
parent 306d9344b2
commit fed98bd9ef
2 changed files with 32 additions and 6 deletions

View File

@@ -47,7 +47,7 @@ class Tests_DB_Charset extends WP_UnitTestCase {
self::$db_server_info = self::$_wpdb->db_server_info();
// Account for MariaDB version being prefixed with '5.5.5-' on older PHP versions.
if ( str_contains( self::$db_server_info, 'MariaDB' ) && '5.5.5' === self::$db_version
if ( '5.5.5' === self::$db_version && str_contains( self::$db_server_info, 'MariaDB' )
&& PHP_VERSION_ID < 80016 // PHP 8.0.15 or older.
) {
// Strip the '5.5.5-' prefix and set the version to the correct value.
@@ -1189,4 +1189,20 @@ class Tests_DB_Charset extends WP_UnitTestCase {
self::$_wpdb->set_charset( self::$_wpdb->dbh );
}
/**
* @ticket 54841
*/
public function test_mariadb_supports_utf8mb4_520() {
global $wpdb;
// utf8mb4_520 is available in MariaDB since version 10.2.
if ( ! str_contains( self::$db_server_info, 'MariaDB' )
|| version_compare( self::$db_version, '10.2', '<' )
) {
$this->markTestSkipped( 'This test requires MariaDB 10.2 or later.' );
}
$this->assertTrue( $wpdb->has_cap( 'utf8mb4_520' ) );
}
}