Commit d41473f3 authored by unknown's avatar unknown

Fix error in parsing string literals containing a backslash followed

by a multi-byte character with a second byte of 0x5c (\). (Bug #8903)


sql/sql_lex.cc:
  Fix lex error when multi-byte character containing 0x5c (\) follows a
  backslash
mysql-test/t/ctype_sjis.test:
  Add regression test for Bug #8303
mysql-test/r/ctype_sjis.result:
  Add test results
parent d743b102
...@@ -91,3 +91,7 @@ sjis_bin 6109 ...@@ -91,3 +91,7 @@ sjis_bin 6109
sjis_bin 61 sjis_bin 61
sjis_bin 6120 sjis_bin 6120
drop table t1; drop table t1;
SET NAMES sjis;
SELECT HEX('佐淘 \圭') FROM DUAL;
HEX('佐淘 \圭')
8DB2939181408C5C
...@@ -68,3 +68,10 @@ SET collation_connection='sjis_japanese_ci'; ...@@ -68,3 +68,10 @@ SET collation_connection='sjis_japanese_ci';
-- source include/ctype_filesort.inc -- source include/ctype_filesort.inc
SET collation_connection='sjis_bin'; SET collation_connection='sjis_bin';
-- source include/ctype_filesort.inc -- source include/ctype_filesort.inc
# Check parsing of string literals in SJIS with multibyte characters that
# have an embedded \ in them. (Bug #8303)
--character_set sjis
SET NAMES sjis;
SELECT HEX('@\\') FROM DUAL;
...@@ -295,7 +295,18 @@ static char *get_text(LEX *lex) ...@@ -295,7 +295,18 @@ static char *get_text(LEX *lex)
found_escape=1; found_escape=1;
if (lex->ptr == lex->end_of_query) if (lex->ptr == lex->end_of_query)
return 0; return 0;
yySkip(); #ifdef USE_MB
int l;
if (use_mb(cs) &&
(l = my_ismbchar(cs,
(const char *)lex->ptr,
(const char *)lex->end_of_query))) {
lex->ptr += l;
continue;
}
else
#endif
yySkip();
} }
else if (c == sep) else if (c == sep)
{ {
...@@ -323,6 +334,10 @@ static char *get_text(LEX *lex) ...@@ -323,6 +334,10 @@ static char *get_text(LEX *lex)
else else
{ {
uchar *to; uchar *to;
/* Re-use found_escape for tracking state of escapes */
found_escape= 0;
for (to=start ; str != end ; str++) for (to=start ; str != end ; str++)
{ {
#ifdef USE_MB #ifdef USE_MB
...@@ -336,7 +351,7 @@ static char *get_text(LEX *lex) ...@@ -336,7 +351,7 @@ static char *get_text(LEX *lex)
continue; continue;
} }
#endif #endif
if (*str == '\\' && str+1 != end) if (!found_escape && *str == '\\' && str+1 != end)
{ {
switch(*++str) { switch(*++str) {
case 'n': case 'n':
...@@ -362,15 +377,20 @@ static char *get_text(LEX *lex) ...@@ -362,15 +377,20 @@ static char *get_text(LEX *lex)
*to++= '\\'; // remember prefix for wildcard *to++= '\\'; // remember prefix for wildcard
/* Fall through */ /* Fall through */
default: default:
*to++ = *str; found_escape= 1;
str--;
break; break;
} }
} }
else if (*str == sep) else if (!found_escape && *str == sep)
*to++= *str++; // Two ' or " {
found_escape= 1;
}
else else
{
*to++ = *str; *to++ = *str;
found_escape= 0;
}
} }
*to=0; *to=0;
lex->yytoklen=(uint) (to-start); lex->yytoklen=(uint) (to-start);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment