From d70805d359fcc1cff8d52b5fb96987e6a41947ad Mon Sep 17 00:00:00 2001 From: Rahim Kanji Date: Mon, 30 Mar 2026 23:47:51 +0500 Subject: [PATCH] Handle utf8/utf8mb3 charset equivalence in test_set_collation MySQL 8.4 reports 'utf8mb3' where older versions report 'utf8'. Add charset_equiv() to treat both names and their collations (e.g. utf8_general_ci vs utf8mb3_general_ci) as equivalent so the test passes on both MySQL 5.7 and 8.4 backends. --- test/tap/tests/test_set_collation-t.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/test/tap/tests/test_set_collation-t.cpp b/test/tap/tests/test_set_collation-t.cpp index cc3a6df4b..5e90d37f2 100644 --- a/test/tap/tests/test_set_collation-t.cpp +++ b/test/tap/tests/test_set_collation-t.cpp @@ -79,18 +79,28 @@ int run_change_user_on_all(const CommandLine& cl, const std::vector return 0; } +static bool charset_equiv(const char* a, const char* b) { + if (strcmp(a, b) == 0) return true; + std::string sa(a), sb(b); + if ((sa == "utf8" && sb == "utf8mb3") || (sa == "utf8mb3" && sb == "utf8")) return true; + // collation equivalence: utf8_general_ci == utf8mb3_general_ci + if (sa.rfind("utf8_", 0) == 0 && sb == "utf8mb3" + sa.substr(4)) return true; + if (sb.rfind("utf8_", 0) == 0 && sa == "utf8mb3" + sb.substr(4)) return true; + return false; +} + void check_variables(MYSQL_RES *proxy_res, std::string collation) { std::size_t found = collation.find("_"); std::string charset = collation.substr(0,found); MYSQL_ROW row = mysql_fetch_row(proxy_res); - ok(strcmp(row[1], charset.c_str()) == 0, "'character_set_client' matches (expected: '%s') == (actual: '%s')", charset.c_str(), row[1]); + ok(charset_equiv(row[1], charset.c_str()), "'character_set_client' matches (expected: '%s') == (actual: '%s')", charset.c_str(), row[1]); row = mysql_fetch_row(proxy_res); - ok(strcmp(row[1], charset.c_str()) == 0, "'character_set_connection' matches (expected: '%s') == (actual: '%s')", charset.c_str(), row[1]); + ok(charset_equiv(row[1], charset.c_str()), "'character_set_connection' matches (expected: '%s') == (actual: '%s')", charset.c_str(), row[1]); row = mysql_fetch_row(proxy_res); - ok(strcmp(row[1], charset.c_str()) == 0, "'character_set_results' matches (expected: '%s') == (actual: '%s')", charset.c_str(), row[1]); + ok(charset_equiv(row[1], charset.c_str()), "'character_set_results' matches (expected: '%s') == (actual: '%s')", charset.c_str(), row[1]); row = mysql_fetch_row(proxy_res); - ok(strcmp(row[1], collation.c_str()) == 0, "'collation_connection' matches (expected: '%s') == (actual: '%s')", collation.c_str(), row[1]); + ok(charset_equiv(row[1], collation.c_str()), "'collation_connection' matches (expected: '%s') == (actual: '%s')", collation.c_str(), row[1]); }