-
Notifications
You must be signed in to change notification settings - Fork 73
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
feat: Add support for escaping characters in KQL key names. #560
Changes from 4 commits
33d13f0
c84c771
723d49d
e8cb65c
3714295
56b89c9
a62542b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -212,8 +212,9 @@ class StringUtils { | |
* @param descriptor | ||
* @param tokens | ||
* @return the list of tokens pushed into the 'tokens' parameter | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Taking that out. |
||
* @return true if the descriptor was tokenized successfully, false otherwise | ||
*/ | ||
static void | ||
[[nodiscard]] static bool | ||
tokenize_column_descriptor(std::string const& descriptor, std::vector<std::string>& tokens); | ||
|
||
private: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,7 +96,7 @@ fragment ESCAPED_SPACE | |
; | ||
|
||
fragment SPECIAL_CHARACTER | ||
: [\\():<>"*?{}] | ||
: [\\():<>"*?{}.] | ||
; | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,4 +187,44 @@ TEST_CASE("Test parsing KQL", "[KQL]") { | |
auto failure = parse_kql_expression(incorrect_query); | ||
REQUIRE(nullptr == failure); | ||
} | ||
|
||
SECTION("Escape sequences in column name") { | ||
auto query = GENERATE( | ||
"a\\.b.c: *", | ||
"\"a\\.b.c\": *", | ||
"a\\.b: {c: *}", | ||
"\"a\\.b\": {\"c\": *}" | ||
); | ||
stringstream escaped_column_query{query}; | ||
auto filter | ||
= std::dynamic_pointer_cast<FilterExpr>(parse_kql_expression(escaped_column_query)); | ||
REQUIRE(nullptr != filter); | ||
REQUIRE(nullptr != filter->get_operand()); | ||
REQUIRE(nullptr != filter->get_column()); | ||
REQUIRE(false == filter->has_only_expression_operands()); | ||
REQUIRE(false == filter->is_inverted()); | ||
REQUIRE(FilterOperation::EQ == filter->get_operation()); | ||
REQUIRE(2 == filter->get_column()->get_descriptor_list().size()); | ||
auto it = filter->get_column()->descriptor_begin(); | ||
SPDLOG_INFO("{}", it->get_token()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to print logs for the test case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. Will remove this. |
||
REQUIRE(DescriptorToken{"a.b"} == *it++); | ||
SPDLOG_INFO("{}", it->get_token()); | ||
REQUIRE(DescriptorToken{"c"} == *it++); | ||
} | ||
|
||
SECTION("Illegal escape sequences in column name") { | ||
auto query = GENERATE( | ||
"a\\:*", | ||
"\"a\\\":*", | ||
"a\\ :*", | ||
"\"a\\\" :*", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the difference between line 218 and 220 (or line 219 and 221)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just confirming that the tokenizing done by ANTLR respects the space really. E.g. if the space were (unexpectedly) included in the column token then it would actually be legal, so we're confirming that this is not the case. |
||
"a.:*", | ||
"\"a.\":*", | ||
"a. :*", | ||
"\"a.\" :*" | ||
); | ||
stringstream illegal_escape{query}; | ||
auto filter = parse_kql_expression(illegal_escape); | ||
REQUIRE(nullptr == filter); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think
.a
is an illegal case at this step, or leave it topopulate_column_mapping
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd agree that it is. Currently the code only complains if the last token is "", but I'll change it to complain if any token is "" and add some tests.