mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 00:22:29 +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 += ".";
|
||||
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:
|
||||
|
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