<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[53918] trunk: Database: Account for `utf8` being renamed to `utf8mb3` in newer MariaDB and MySQL versions.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/53918">53918</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/53918","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>SergeyBiryukov</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2022-08-22 15:37:59 +0000 (Mon, 22 Aug 2022)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Database: Account for `utf8` being renamed to `utf8mb3` in newer MariaDB and MySQL versions.
>From [https://mariadb.com/kb/en/mariadb-1061-release-notes/ MariaDB 10.6.1 release notes]:
> The `utf8` [https://mariadb.com/kb/en/character-sets/ 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 [https://mariadb.com/kb/en/server-system-variables/#old_mode old_mode] system variable ([https://jira.mariadb.org/browse/MDEV-8334 MDEV-8334]).
>From [https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-30.html#mysqld-8-0-30-charset 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:
* [https://mariadb.com/kb/en/mariadb-1061-release-notes/ MariaDB 10.6.1 release notes]
* [https://jira.mariadb.org/browse/MDEV-8334 MDEV-8334 Rename utf8 to utf8mb3]
* [https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-30.html#mysqld-8-0-30-charset MySQL 8.0.30 release notes]
* [https://dev.mysql.com/doc/refman/8.0/en/charset-unicode-utf8mb3.html The utf8mb3 Character Set (3-Byte UTF-8 Unicode Encoding)]
Follow-up to <a href="https://core.trac.wordpress.org/changeset/30345">[30345]</a>, <a href="https://core.trac.wordpress.org/changeset/32162">[32162]</a>, <a href="https://core.trac.wordpress.org/changeset/37320">[37320]</a>.
Props skithund, ayeshrajans, JavierCasares, SergeyBiryukov.
Fixes <a href="https://core.trac.wordpress.org/ticket/53623">#53623</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesclasswpdbphp">trunk/src/wp-includes/class-wpdb.php</a></li>
<li><a href="#trunktestsphpunittestsdbcharsetphp">trunk/tests/phpunit/tests/db/charset.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesclasswpdbphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wpdb.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wpdb.php 2022-08-22 12:24:30 UTC (rev 53917)
+++ trunk/src/wp-includes/class-wpdb.php 2022-08-22 15:37:59 UTC (rev 53918)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3376,12 +3376,21 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // If any of the columns don't have one of these collations, it needs more sanity checking.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $safe_collations = array(
+ 'utf8_bin',
+ 'utf8_general_ci',
+ 'utf8mb3_bin',
+ 'utf8mb3_general_ci',
+ 'utf8mb4_bin',
+ 'utf8mb4_general_ci',
+ );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> foreach ( $this->col_meta[ $table ] as $col ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( empty( $col->Collation ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> continue;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! in_array( $col->Collation, array( 'utf8_general_ci', 'utf8_bin', 'utf8mb4_general_ci', 'utf8mb4_bin' ), true ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! in_array( $col->Collation, $safe_collations, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunktestsphpunittestsdbcharsetphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/db/charset.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/db/charset.php 2022-08-22 12:24:30 UTC (rev 53917)
+++ trunk/tests/phpunit/tests/db/charset.php 2022-08-22 15:37:59 UTC (rev 53918)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -9,7 +9,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> class Tests_DB_Charset extends WP_UnitTestCase {
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Our special WPDB
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Our special WPDB.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @var resource
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -16,12 +16,26 @@
</span><span class="cx" style="display: block; padding: 0 10px"> protected static $_wpdb;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * The version of the MySQL server.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Whether to expect utf8mb3 instead of utf8 in various commands output.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @var bool
+ */
+ private static $utf8_is_utf8mb3 = false;
+
+ /**
+ * The database server version.
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * @var string
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private static $server_info;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ private static $db_version;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Full database server information.
+ *
+ * @var string
+ */
+ private static $db_server_info;
+
</ins><span class="cx" style="display: block; padding: 0 10px"> public static function set_up_before_class() {
</span><span class="cx" style="display: block; padding: 0 10px"> parent::set_up_before_class();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -29,7 +43,18 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> self::$_wpdb = new WpdbExposedMethodsForTesting();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- self::$server_info = self::$_wpdb->db_server_info();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ self::$db_version = self::$_wpdb->db_version();
+ self::$db_server_info = self::$_wpdb->db_server_info();
+
+ /*
+ * MariaDB 10.6.1 or later and MySQL 8.0.30 or later
+ * use utf8mb3 instead of utf8 in various commands output.
+ */
+ if ( str_contains( self::$db_server_info, 'MariaDB' ) && version_compare( self::$db_version, '10.6.1', '>=' )
+ || ! str_contains( self::$db_server_info, 'MariaDB' ) && version_compare( self::$db_version, '8.0.30', '>=' )
+ ) {
+ self::$utf8_is_utf8mb3 = true;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -492,7 +517,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->markTestSkipped( "The current MySQL server doesn't support the utf8mb4 character set." );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( 'big5' === $new_charset && 'byte' === $data[0]['length']['type'] && false !== strpos( self::$server_info, 'MariaDB' ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( 'big5' === $new_charset && 'byte' === $data[0]['length']['type']
+ && str_contains( self::$db_server_info, 'MariaDB' )
+ ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->markTestSkipped( "MariaDB doesn't support this data set. See https://core.trac.wordpress.org/ticket/33171." );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -808,6 +835,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> self::$_wpdb->query( $create );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $expected_charset as $column => $charset ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( self::$utf8_is_utf8mb3 && 'utf8' === $charset ) {
+ $charset = 'utf8mb3';
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->assertSame( $charset, self::$_wpdb->get_col_charset( $table, $column ) );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertSame( $charset, self::$_wpdb->get_col_charset( strtoupper( $table ), strtoupper( $column ) ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -875,27 +906,29 @@
</span><span class="cx" style="display: block; padding: 0 10px"> public function data_strip_invalid_text_from_query() {
</span><span class="cx" style="display: block; padding: 0 10px"> $table_name = 'strip_invalid_text_from_query_table';
</span><span class="cx" style="display: block; padding: 0 10px"> $data = array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'utf8 + binary' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> // Binary tables don't get stripped.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- '( a VARCHAR(50) CHARACTER SET utf8, b BINARY )', // Create.
- "('foo\xf0\x9f\x98\x88bar', 'foo')", // Query.
- "('foo\xf0\x9f\x98\x88bar', 'foo')", // Expected result.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'create' => '( a VARCHAR(50) CHARACTER SET utf8, b BINARY )',
+ 'query' => "('foo\xf0\x9f\x98\x88bar', 'foo')",
+ 'expected' => "('foo\xf0\x9f\x98\x88bar', 'foo')",
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'utf8 + utf8mb4' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> // utf8/utf8mb4 tables default to utf8.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- '( a VARCHAR(50) CHARACTER SET utf8, b VARCHAR(50) CHARACTER SET utf8mb4 )',
- "('foo\xf0\x9f\x98\x88bar', 'foo')",
- "('foobar', 'foo')",
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'create' => '( a VARCHAR(50) CHARACTER SET utf8, b VARCHAR(50) CHARACTER SET utf8mb4 )',
+ 'query' => "('foo\xf0\x9f\x98\x88bar', 'foo')",
+ 'expected' => "('foobar', 'foo')",
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- foreach ( $data as $i => &$value ) {
- $this_table_name = $table_name . '_' . $i;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $i = 0;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $value[0] = "CREATE TABLE $this_table_name {$value[0]}";
- $value[1] = "INSERT INTO $this_table_name VALUES {$value[1]}";
- $value[2] = "INSERT INTO $this_table_name VALUES {$value[2]}";
- $value[3] = "DROP TABLE IF EXISTS $this_table_name";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ foreach ( $data as &$value ) {
+ $this_table_name = $table_name . '_' . $i++;
+
+ $value['create'] = "CREATE TABLE $this_table_name {$value['create']}";
+ $value['query'] = "INSERT INTO $this_table_name VALUES {$value['query']}";
+ $value['expected'] = "INSERT INTO $this_table_name VALUES {$value['expected']}";
+ $value['drop'] = "DROP TABLE IF EXISTS $this_table_name";
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> unset( $value );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -979,42 +1012,44 @@
</span><span class="cx" style="display: block; padding: 0 10px"> public function data_table_collation_check() {
</span><span class="cx" style="display: block; padding: 0 10px"> $table_name = 'table_collation_check';
</span><span class="cx" style="display: block; padding: 0 10px"> $data = array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'utf8_bin' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> // utf8_bin tables don't need extra sanity checking.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- '( a VARCHAR(50) COLLATE utf8_bin )', // Create.
- true, // Expected result.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'create' => '( a VARCHAR(50) COLLATE utf8_bin )',
+ 'expected' => true,
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'utf8_general_ci' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> // Neither do utf8_general_ci tables.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- '( a VARCHAR(50) COLLATE utf8_general_ci )',
- true,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'create' => '( a VARCHAR(50) COLLATE utf8_general_ci )',
+ 'expected' => true,
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'utf8_unicode_ci' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> // utf8_unicode_ci tables do.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- '( a VARCHAR(50) COLLATE utf8_unicode_ci )',
- false,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'create' => '( a VARCHAR(50) COLLATE utf8_unicode_ci )',
+ 'expected' => false,
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'utf8_bin + big5_chinese_ci' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> // utf8_bin tables don't need extra sanity checking,
</span><span class="cx" style="display: block; padding: 0 10px"> // except for when they're not just utf8_bin.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- '( a VARCHAR(50) COLLATE utf8_bin, b VARCHAR(50) COLLATE big5_chinese_ci )',
- false,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'create' => '( a VARCHAR(50) COLLATE utf8_bin, b VARCHAR(50) COLLATE big5_chinese_ci )',
+ 'expected' => false,
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'utf8_bin + int' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> // utf8_bin tables don't need extra sanity checking
</span><span class="cx" style="display: block; padding: 0 10px"> // when the other columns aren't strings.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- '( a VARCHAR(50) COLLATE utf8_bin, b INT )',
- true,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'create' => '( a VARCHAR(50) COLLATE utf8_bin, b INT )',
+ 'expected' => true,
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- foreach ( $data as $i => &$value ) {
- $this_table_name = $table_name . '_' . $i;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $i = 0;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $value[0] = "CREATE TABLE $this_table_name {$value[0]}";
- $value[2] = "SELECT * FROM $this_table_name WHERE a='\xf0\x9f\x98\x88'";
- $value[3] = "DROP TABLE IF EXISTS $this_table_name";
- $value[4] = array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ foreach ( $data as &$value ) {
+ $this_table_name = $table_name . '_' . $i++;
+
+ $value['create'] = "CREATE TABLE $this_table_name {$value['create']}";
+ $value['query'] = "SELECT * FROM $this_table_name WHERE a='\xf0\x9f\x98\x88'";
+ $value['drop'] = "DROP TABLE IF EXISTS $this_table_name";
+ $value['always_true'] = array(
</ins><span class="cx" style="display: block; padding: 0 10px"> "SELECT * FROM $this_table_name WHERE a='foo'",
</span><span class="cx" style="display: block; padding: 0 10px"> "SHOW FULL TABLES LIKE $this_table_name",
</span><span class="cx" style="display: block; padding: 0 10px"> "DESCRIBE $this_table_name",
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1040,11 +1075,31 @@
</span><span class="cx" style="display: block; padding: 0 10px"> self::$_wpdb->query( $create );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $return = self::$_wpdb->check_safe_collation( $query );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertSame( $expected, $return );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertSame(
+ $expected,
+ $return,
+ sprintf(
+ "wpdb::check_safe_collation() should return %s for this query.\n" .
+ "Table: %s\n" .
+ 'Query: %s',
+ $expected ? 'true' : 'false',
+ $create,
+ $query
+ )
+ );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $always_true as $true_query ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $return = self::$_wpdb->check_safe_collation( $true_query );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertTrue( $return );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertTrue(
+ $return,
+ sprintf(
+ "wpdb::check_safe_collation() should return true for this query.\n" .
+ "Table: %s\n" .
+ 'Query: %s',
+ $create,
+ $true_query
+ )
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> self::$_wpdb->query( $drop );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1115,12 +1170,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_set_charset_changes_the_connection_collation() {
</span><span class="cx" style="display: block; padding: 0 10px"> self::$_wpdb->set_charset( self::$_wpdb->dbh, 'utf8', 'utf8_general_ci' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $results = self::$_wpdb->get_results( "SHOW VARIABLES WHERE Variable_name='collation_connection'" );
- $this->assertSame( 'utf8_general_ci', $results[0]->Value );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $results = self::$_wpdb->get_results( "SHOW VARIABLES WHERE Variable_name='collation_connection'" );
+ $expected = self::$utf8_is_utf8mb3 ? 'utf8mb3_general_ci' : 'utf8_general_ci';
+ $this->assertSame( $expected, $results[0]->Value, "Collation should be set to $expected." );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> self::$_wpdb->set_charset( self::$_wpdb->dbh, 'utf8mb4', 'utf8mb4_unicode_ci' );
</span><span class="cx" style="display: block; padding: 0 10px"> $results = self::$_wpdb->get_results( "SHOW VARIABLES WHERE Variable_name='collation_connection'" );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertSame( 'utf8mb4_unicode_ci', $results[0]->Value );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertSame( 'utf8mb4_unicode_ci', $results[0]->Value, 'Collation should be set to utf8mb4_unicode_ci.' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> self::$_wpdb->set_charset( self::$_wpdb->dbh );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>
</body>
</html>