mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-19 16:20:50 +00:00
Merge pull request #68451 from Avogar/check-json-regexp
Check for invalid regexp in JSON SKIP REGEXP section
This commit is contained in:
commit
054b38d4eb
@ -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)
|
||||||
|
4
tests/queries/0_stateless/03227_json_invalid_regexp.sql
Normal file
4
tests/queries/0_stateless/03227_json_invalid_regexp.sql
Normal 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};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user