Skip to content

Commit

Permalink
Merge pull request #52160 from ClickHouse/fix-has-token
Browse files Browse the repository at this point in the history
Add a check for `hasToken`
  • Loading branch information
KochetovNicolai committed Jul 18, 2023
2 parents 32b9d39 + 218a1c7 commit 51c65e3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Functions/HasTokenImpl.h
Expand Up @@ -39,6 +39,9 @@ struct HasTokenImpl
if (start_pos != nullptr)
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Function '{}' does not support start_pos argument", name);

if (pattern.empty())
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Needle cannot be empty, because empty string isn't a token");

if (haystack_offsets.empty())
return;

Expand Down
2 changes: 2 additions & 0 deletions tests/queries/0_stateless/02816_has_token_empty.reference
@@ -0,0 +1,2 @@
0
0
7 changes: 7 additions & 0 deletions tests/queries/0_stateless/02816_has_token_empty.sql
@@ -0,0 +1,7 @@
SELECT hasTokenCaseInsensitive('K(G', ''); -- { serverError BAD_ARGUMENTS }
SELECT hasTokenCaseInsensitive('Hello', ''); -- { serverError BAD_ARGUMENTS }
SELECT hasTokenCaseInsensitive('', ''); -- { serverError BAD_ARGUMENTS }
SELECT hasTokenCaseInsensitive('', 'Hello');
SELECT hasToken('Hello', ''); -- { serverError BAD_ARGUMENTS }
SELECT hasToken('', 'Hello');
SELECT hasToken('', ''); -- { serverError BAD_ARGUMENTS }

0 comments on commit 51c65e3

Please sign in to comment.