From d843b636001ac455fb545c44085189cb28154128 Mon Sep 17 00:00:00 2001 From: SharafMohamed Date: Thu, 5 Feb 2026 07:55:52 -0500 Subject: [PATCH] Temporarily disallow capture groups. --- components/core/src/clp/Utils.cpp | 9 ++- components/core/src/clp/clp/run.cpp | 10 ++++ .../core/tests/test-ParserWithUserSchema.cpp | 55 ++++++------------- 3 files changed, 30 insertions(+), 44 deletions(-) diff --git a/components/core/src/clp/Utils.cpp b/components/core/src/clp/Utils.cpp index 750e5d4579..382215cf44 100644 --- a/components/core/src/clp/Utils.cpp +++ b/components/core/src/clp/Utils.cpp @@ -184,14 +184,13 @@ load_lexer_from_file(std::string const& schema_file_path, log_surgeon::lexers::B for (std::unique_ptr const& parser_ast : schema_ast->m_schema_vars) { auto* rule = dynamic_cast(parser_ast.get()); - // Currently, we only support at most a single capture group in each variable. If a capture - // group is present its match will be treated as the variable rather than the full match. - auto const num_captures = rule->m_regex_ptr->get_subtree_positive_captures().size(); - if (1 < num_captures) { + // Capture groups are temporarily disabled, until NFA intersection supports for search. + auto const num_captures{rule->m_regex_ptr->get_subtree_positive_captures().size()}; + if (0 < num_captures) { throw std::runtime_error( schema_file_path + ":" + std::to_string(rule->m_line_num + 1) + ": error: the schema rule '" + rule->m_name - + "' has a regex pattern containing > 1 capture groups (found " + + "' has a regex pattern containing capture groups (found " + std::to_string(num_captures) + ").\n" ); } diff --git a/components/core/src/clp/clp/run.cpp b/components/core/src/clp/clp/run.cpp index b70bf45ff4..09e3475c94 100644 --- a/components/core/src/clp/clp/run.cpp +++ b/components/core/src/clp/clp/run.cpp @@ -61,6 +61,16 @@ int run(int argc, char const* argv[]) { if (!command_line_args.get_use_heuristic()) { std::string const& schema_file_path = command_line_args.get_schema_file_path(); reader_parser = std::make_unique(schema_file_path); + // Capture groups are temporarily disabled, until NFA intersection support for search. + auto const& lexer{reader_parser->get_log_parser().m_lexer}; + for (auto const& [rule_id, rule_name] : lexer.m_id_symbol) { + if (lexer.get_captures_from_rule_id(rule_id).has_value()) { + throw std::runtime_error( + schema_file_path + ": error: the schema rule '" + rule_name + + "' has a regex pattern containing capture groups.\n" + ); + } + } } boost::filesystem::path path_prefix_to_remove( diff --git a/components/core/tests/test-ParserWithUserSchema.cpp b/components/core/tests/test-ParserWithUserSchema.cpp index d4dd71970b..a74de6d8a3 100644 --- a/components/core/tests/test-ParserWithUserSchema.cpp +++ b/components/core/tests/test-ParserWithUserSchema.cpp @@ -191,16 +191,15 @@ TEST_CASE("Test lexer", "[Search]") { } } -TEST_CASE("Test schema with single capture group", "[load_lexer]") { +TEST_CASE("Error on schema rule with a single capture group", "[load_lexer]") { auto const schema_file_path{get_test_schema_files_dir() / "single_capture_group.txt"}; ByteLexer lexer; - load_lexer_from_file(schema_file_path, lexer); - - auto const rule_id{lexer.m_symbol_id.at("capture")}; - auto captures{lexer.get_captures_from_rule_id(rule_id)}; - REQUIRE(captures.has_value()); - REQUIRE(1 == captures->size()); - REQUIRE("group" == captures->at(0)->get_name()); + REQUIRE_THROWS_WITH( + load_lexer_from_file(schema_file_path, lexer), + schema_file_path.string() + + ":3: error: the schema rule 'capture' has a regex pattern containing capture " + "groups (found 1).\n" + ); } TEST_CASE("Error on schema rule with multiple capture groups", "[load_lexer]") { @@ -209,43 +208,21 @@ TEST_CASE("Error on schema rule with multiple capture groups", "[load_lexer]") { REQUIRE_THROWS_WITH( load_lexer_from_file(schema_file_path, lexer), schema_file_path.string() - + ":3: error: the schema rule 'multicapture' has a regex pattern containing > " - "1 capture groups (found 2).\n" + + ":3: error: the schema rule 'multicapture' has a regex pattern containing " + "capture groups (found 2).\n" ); } -TEST_CASE("Verify dictionary contents", "[Compression]") { +TEST_CASE("Verify CLP compression fails with capture groups", "[Compression]") { auto const log_file_path{get_test_log_dir() / "log_with_capture.txt"}; auto const schema_file_path{get_test_schema_files_dir() / "single_capture_group.txt"}; TestOutputCleaner const cleaner{{std::string{cTestArchiveDirectory}}}; std::filesystem::create_directory(cTestArchiveDirectory); - REQUIRE(0 == run_clp_compress(schema_file_path, cTestArchiveDirectory, log_file_path)); - - std::vector archive_paths; - for (auto const& entry : std::filesystem::directory_iterator{cTestArchiveDirectory}) { - auto const& path{entry.path()}; - if (false == path.string().ends_with(clp::streaming_archive::cMetadataDBFileName)) { - archive_paths.emplace_back(path); - } - } - REQUIRE(1 == archive_paths.size()); - - clp::streaming_archive::reader::Archive archive_reader; - archive_reader.open(archive_paths.at(0)); - archive_reader.refresh_dictionaries(); - - auto const& logtype_dict{archive_reader.get_logtype_dictionary()}; - REQUIRE(1 == logtype_dict.get_entries().size()); - REQUIRE(fmt::format( - "2016-05-08 07:34:05.251 MyDog{} APet{} test.txt\n", - clp::enum_to_underlying_type(clp::ir::VariablePlaceholder::Dictionary), - clp::enum_to_underlying_type(clp::ir::VariablePlaceholder::Dictionary) - ) - == logtype_dict.get_value(0)); - - auto const& var_dict{archive_reader.get_var_dictionary()}; - REQUIRE(2 == var_dict.get_entries().size()); - REQUIRE("123" == var_dict.get_value(0)); - REQUIRE("4123" == var_dict.get_value(1)); + REQUIRE_THROWS_WITH( + run_clp_compress(schema_file_path, cTestArchiveDirectory, log_file_path), + schema_file_path.string() + + ": error: the schema rule 'capture' has a regex pattern containing capture " + "groups.\n" + ); }