Skip to content

Commit

Permalink
Admin check: fix MySQL UTF-8 collation check
Browse files Browse the repository at this point in the history
MySQL 5.5.3 introduced the 'utf8mb4' character which allows storage of
up to 4-byte unicode characters (utf8 only allows 3 bytes) [1].

As a consequence, the current check for collation beginning with 'utf8_'
returns false if the collation is utf8mb4.

This adds a new check_api check_is_collation_utf8() function to ensure
consistent checking of collation, and removes the underscore from the
comparison string.

Fixes #20426

[1] https://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8mb4.html
  • Loading branch information
dregad committed Jan 1, 2016
1 parent b5c53a3 commit 8148a3d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions admin/check/check_api.php
Expand Up @@ -265,3 +265,12 @@ function check_print_test_warn_row( $p_description, $p_pass, $p_info = null ) {
$g_alternate_row = $g_alternate_row === 1 ? 2 : 1;
return $p_pass;
}

/**
* Verifies that the given collation is UTF-8
* @param string $p_collation
* @return boolean True if UTF-8
*/
function check_is_collation_utf8( $p_collation ) {
return substr( $p_collation, 0, 4 ) === 'utf8';
}
4 changes: 2 additions & 2 deletions admin/check/check_database_inc.php
Expand Up @@ -364,7 +364,7 @@
) {
check_print_test_row(
'Table <em>' . htmlentities( $t_row['name'] ) . '</em> is using UTF-8 collation',
substr( $t_row['collation'], 0, 5 ) === 'utf8_',
check_is_collation_utf8( $t_row['collation'] ),
array( false => 'Table ' . htmlentities( $t_row['name'] )
. ' is using ' . htmlentities( $t_row['collation'] )
. ' collation where UTF-8 collation is required.' ) );
Expand All @@ -383,7 +383,7 @@
. '</em> of type <em>' . $t_row['type']
. '</em> on table <em>' . htmlentities( $t_table )
. '</em> is is using UTF-8 collation',
substr( $t_row['collation'], 0, 5 ) === 'utf8_',
check_is_collation_utf8( $t_row['collation'] ),
array( false => 'Text column ' . htmlentities( $t_row['field'] )
. ' of type ' . $t_row['type']
. ' on table ' . htmlentities( $t_table )
Expand Down

0 comments on commit 8148a3d

Please sign in to comment.