Fix error in LIKE (found by SQLancer)

This commit is contained in:
Alexey Milovidov 2021-04-25 03:58:44 +03:00
parent 601108fb1c
commit 263378bb20
3 changed files with 67 additions and 9 deletions

View File

@ -36,18 +36,21 @@ inline String likePatternToRegexp(const String & pattern)
res += ".";
break;
case '\\':
/// Known escape sequences.
if (pos + 1 != end && (pos[1] == '%' || pos[1] == '_'))
{
res += pos[1];
++pos;
if (pos == end)
res += "\\\\";
else
{
if (*pos == '%' || *pos == '_')
res += *pos;
else
{
res += '\\';
res += *pos;
}
else if (pos + 1 != end && pos[1] == '\\')
{
res += "\\\\";
++pos;
}
else
{
/// Unknown escape sequence treated literally: as backslash and the following character.
res += "\\\\";
}
break;
default:

View File

@ -0,0 +1,25 @@
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

View File

@ -0,0 +1,30 @@
SELECT '\w' LIKE '%\w%';
SELECT '\w' LIKE '\w%';
SELECT '\w' LIKE '%\w';
SELECT '\w' LIKE '\w';
SELECT '\\w' LIKE '%\\w%';
SELECT '\\w' LIKE '\\w%';
SELECT '\\w' LIKE '%\\w';
SELECT '\\w' LIKE '\\w';
SELECT '\i' LIKE '%\i%';
SELECT '\i' LIKE '\i%';
SELECT '\i' LIKE '%\i';
SELECT '\i' LIKE '\i';
SELECT '\\i' LIKE '%\\i%';
SELECT '\\i' LIKE '\\i%';
SELECT '\\i' LIKE '%\\i';
SELECT '\\i' LIKE '\\i';
SELECT '\\' LIKE '%\\\\%';
SELECT '\\' LIKE '\\\\%';
SELECT '\\' LIKE '%\\\\';
SELECT '\\' LIKE '\\\\';
SELECT '\\' LIKE '\\';
SELECT '\\xyz\\' LIKE '\\\\%\\\\';
SELECT '\\xyz\\' LIKE '\\\\___\\\\';
SELECT '\\xyz\\' LIKE '\\\\_%_\\\\';
SELECT '\\xyz\\' LIKE '\\\\%_%\\\\';