summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorunknown <jimw@mysql.com>2005-02-09 16:14:13 -0800
committerunknown <jimw@mysql.com>2005-02-09 16:14:13 -0800
commitae14393e7487f3c8a97f3dc44cab7a2c19cdd0a9 (patch)
treefc0e31ce18ee1b43ae86ca71d4120e68d998d2e2 /tests
parent37e2873fe38db47548ecac5bd3afaac23b8791be (diff)
downloadmariadb-git-ae14393e7487f3c8a97f3dc44cab7a2c19cdd0a9.tar.gz
When escaping a string in a multi-byte character set, escape all bytes of
a character that appears to be a multi-byte character based on its first byte, but is not actually a valid multi-byte character. (Bug #8378) tests/mysql_client_test.c: Add test for Bug #8317 mysys/charset.c: Properly escape invalid multibyte characters.
Diffstat (limited to 'tests')
-rw-r--r--tests/mysql_client_test.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c
index 83f8f6ab143..b7e3e1b3469 100644
--- a/tests/mysql_client_test.c
+++ b/tests/mysql_client_test.c
@@ -11533,6 +11533,54 @@ static void test_bug6761(void)
}
/*
+ Test mysql_real_escape_string() with gbk charset
+
+ The important part is that 0x27 (') is the second-byte in a invvalid
+ two-byte GBK character here. But 0xbf5c is a valid GBK character, so
+ it needs to be escaped as 0x5cbf5c27
+*/
+#define TEST_BUG8317_IN "\xef\xbb\xbf\x27"
+#define TEST_BUG8317_OUT "\xef\xbb\x5c\xbf\x5c\x27"
+
+static void test_bug8317()
+{
+ MYSQL *lmysql;
+ char out[9]; /* strlen(TEST_BUG8317)*2+1 */
+ int len;
+
+ myheader("test_bug8317");
+
+ if (!opt_silent)
+ fprintf(stdout, "\n Establishing a test connection ...");
+ if (!(lmysql= mysql_init(NULL)))
+ {
+ myerror("mysql_init() failed");
+ exit(1);
+ }
+ if (mysql_options(lmysql, MYSQL_SET_CHARSET_NAME, "gbk"))
+ {
+ myerror("mysql_options() failed");
+ exit(1);
+ }
+ if (!(mysql_real_connect(lmysql, opt_host, opt_user,
+ opt_password, current_db, opt_port,
+ opt_unix_socket, 0)))
+ {
+ myerror("connection failed");
+ exit(1);
+ }
+ if (!opt_silent)
+ fprintf(stdout, " OK");
+
+ len= mysql_real_escape_string(lmysql, out, TEST_BUG8317_IN, 4);
+
+ /* No escaping should have actually happened. */
+ DIE_UNLESS(memcmp(out, TEST_BUG8317_OUT, len) == 0);
+
+ mysql_close(lmysql);
+}
+
+/*
Read and parse arguments and MySQL options from my.cnf
*/
@@ -11739,6 +11787,7 @@ static struct my_tests_st my_tests[]= {
{ "test_conversion", test_conversion },
{ "test_rewind", test_rewind },
{ "test_bug6761", test_bug6761 },
+ { "test_bug8317", test_bug8317 },
{ 0, 0 }
};