Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a check for hasToken #52160

Merged
merged 3 commits into from Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 }