Merge pull request #68451 from Avogar/check-json-regexp

Check for invalid regexp in JSON SKIP REGEXP section
This commit is contained in:
Kruglov Pavel 2024-08-20 19:48:36 +00:00 committed by GitHub
commit 054b38d4eb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 0 deletions

View File

@ -35,6 +35,7 @@ namespace ErrorCodes
{ {
extern const int UNEXPECTED_AST_STRUCTURE; extern const int UNEXPECTED_AST_STRUCTURE;
extern const int BAD_ARGUMENTS; extern const int BAD_ARGUMENTS;
extern const int CANNOT_COMPILE_REGEXP;
} }
DataTypeObject::DataTypeObject( DataTypeObject::DataTypeObject(
@ -51,6 +52,17 @@ DataTypeObject::DataTypeObject(
, max_dynamic_paths(max_dynamic_paths_) , max_dynamic_paths(max_dynamic_paths_)
, max_dynamic_types(max_dynamic_types_) , max_dynamic_types(max_dynamic_types_)
{ {
/// Check if regular expressions are valid.
for (const auto & regexp_str : path_regexps_to_skip)
{
re2::RE2::Options options;
/// Don't log errors to stderr.
options.set_log_errors(false);
auto regexp = re2::RE2(regexp_str, options);
if (!regexp.ok())
throw Exception(ErrorCodes::CANNOT_COMPILE_REGEXP, "Invalid regexp '{}': {}", regexp_str, regexp.error());
}
for (const auto & [typed_path, type] : typed_paths) for (const auto & [typed_path, type] : typed_paths)
{ {
for (const auto & path_to_skip : paths_to_skip) for (const auto & path_to_skip : paths_to_skip)

View File

@ -0,0 +1,4 @@
set allow_experimental_json_type = 1;
create table test (json JSON(SKIP REGEXP '[]')) engine=Memory(); -- {serverError CANNOT_COMPILE_REGEXP}
create table test (json JSON(SKIP REGEXP '+')) engine=Memory(); -- {serverError CANNOT_COMPILE_REGEXP};