mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
Fix error in LIKE (found by SQLancer)
This commit is contained in:
parent
601108fb1c
commit
263378bb20
@ -36,18 +36,21 @@ inline String likePatternToRegexp(const String & pattern)
|
|||||||
res += ".";
|
res += ".";
|
||||||
break;
|
break;
|
||||||
case '\\':
|
case '\\':
|
||||||
++pos;
|
/// Known escape sequences.
|
||||||
if (pos == end)
|
if (pos + 1 != end && (pos[1] == '%' || pos[1] == '_'))
|
||||||
|
{
|
||||||
|
res += pos[1];
|
||||||
|
++pos;
|
||||||
|
}
|
||||||
|
else if (pos + 1 != end && pos[1] == '\\')
|
||||||
|
{
|
||||||
res += "\\\\";
|
res += "\\\\";
|
||||||
|
++pos;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (*pos == '%' || *pos == '_')
|
/// Unknown escape sequence treated literally: as backslash and the following character.
|
||||||
res += *pos;
|
res += "\\\\";
|
||||||
else
|
|
||||||
{
|
|
||||||
res += '\\';
|
|
||||||
res += *pos;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
25
tests/queries/0_stateless/01847_bad_like.reference
Normal file
25
tests/queries/0_stateless/01847_bad_like.reference
Normal 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
|
30
tests/queries/0_stateless/01847_bad_like.sql
Normal file
30
tests/queries/0_stateless/01847_bad_like.sql
Normal 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 '\\\\%_%\\\\';
|
Loading…
Reference in New Issue
Block a user