Skip to content

Commit 9d66322

Browse files
committed
Merge branch 'main' into bump-ystdlib-cpp
2 parents 57c51c9 + 9aee596 commit 9d66322

File tree

95 files changed

+1517
-386
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+1517
-386
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
__pycache__/
12
.clang-format
23
.clang-tidy
34
.lint-venv/

components/core/src/clp/EncodedVariableInterpreter.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include <unordered_set>
77
#include <vector>
88

9+
#include <string_utils/string_utils.hpp>
10+
911
#include "ffi/ir_stream/decoding_methods.hpp"
1012
#include "ir/LogEvent.hpp"
1113
#include "ir/types.hpp"
@@ -455,7 +457,8 @@ bool EncodedVariableInterpreter::encode_and_search_dictionary(
455457
add_float_var(logtype);
456458
sub_query.add_non_dict_var(encoded_var);
457459
} else {
458-
auto const entries = var_dict.get_entry_matching_value(var_str, ignore_case);
460+
auto const unescaped_var_string{string_utils::unescape_string(var_str)};
461+
auto const entries = var_dict.get_entry_matching_value(unescaped_var_string, ignore_case);
459462
if (entries.empty()) {
460463
// Not in dictionary
461464
return false;

components/core/src/clp/string_utils/string_utils.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include <algorithm>
44
#include <charconv>
55
#include <cstring>
6+
#include <string>
7+
#include <string_view>
68

79
using std::string;
810
using std::string_view;
@@ -188,6 +190,22 @@ string clean_up_wildcard_search_string(string_view str) {
188190
return cleaned_str;
189191
}
190192

193+
auto unescape_string(std::string_view str) -> std::string {
194+
std::string unescaped_str;
195+
bool escaped{false};
196+
for (auto const c : str) {
197+
if (escaped) {
198+
unescaped_str.push_back(c);
199+
escaped = false;
200+
} else if ('\\' == c) {
201+
escaped = true;
202+
} else {
203+
unescaped_str.push_back(c);
204+
}
205+
}
206+
return unescaped_str;
207+
}
208+
191209
bool wildcard_match_unsafe(string_view tame, string_view wild, bool case_sensitive_match) {
192210
if (case_sensitive_match) {
193211
return wildcard_match_unsafe_case_sensitive(tame, wild);

components/core/src/clp/string_utils/string_utils.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <charconv>
55
#include <concepts>
66
#include <string>
7+
#include <string_view>
78

89
namespace clp::string_utils {
910
/**
@@ -87,6 +88,17 @@ void to_lower(std::string& str);
8788
*/
8889
std::string clean_up_wildcard_search_string(std::string_view str);
8990

91+
/**
92+
* Unescapes a string according to the following rules:
93+
* <ul>
94+
* <li>Escape sequences `\<char>` are replaced by `<char>`</li>
95+
* <li>Lone dangling `\` is removed from the end of the string</li>
96+
* </ul>
97+
* @param str
98+
* @return An unescaped version of `str`.
99+
*/
100+
[[nodiscard]] auto unescape_string(std::string_view str) -> std::string;
101+
90102
/**
91103
* Checks if character is a wildcard
92104
* @param c

components/core/src/clp_s/search/QueryRunner.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -886,19 +886,7 @@ void QueryRunner::populate_string_queries(std::shared_ptr<Expression> const& exp
886886

887887
std::unordered_set<int64_t>& matching_vars = m_string_var_match_map[query_string];
888888
if (false == ast::has_unescaped_wildcards(query_string)) {
889-
std::string unescaped_query_string;
890-
bool escape = false;
891-
for (char const c : query_string) {
892-
if (escape) {
893-
unescaped_query_string.push_back(c);
894-
escape = false;
895-
} else if (c == '\\') {
896-
escape = true;
897-
} else {
898-
unescaped_query_string.push_back(c);
899-
}
900-
}
901-
889+
auto const unescaped_query_string{clp::string_utils::unescape_string(query_string)};
902890
auto const entries = m_var_dict->get_entry_matching_value(
903891
unescaped_query_string,
904892
m_ignore_case

components/core/tests/test-EncodedVariableInterpreter.cpp

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#include <unistd.h>
22

3+
#include <string>
4+
#include <string_view>
5+
#include <vector>
6+
37
#include <catch2/catch_test_macros.hpp>
48

59
#include "../src/clp/EncodedVariableInterpreter.hpp"
@@ -15,6 +19,7 @@ using clp::EncodedVariableInterpreter;
1519
using clp::enum_to_underlying_type;
1620
using clp::ir::VariablePlaceholder;
1721
using std::string;
22+
using std::string_view;
1823
using std::to_string;
1924
using std::vector;
2025

@@ -439,14 +444,15 @@ TEST_CASE("EncodedVariableInterpreter", "[EncodedVariableInterpreter]") {
439444

440445
string large_val_str = to_string(cVariableDictionaryIdMax) + "0";
441446
vector<string> var_strs
442-
= {"4938", large_val_str, "-25.5196868642755", "-00.00", "python2.7.3"};
447+
= {"4938", large_val_str, "-25.5196868642755", "-00.00", "python2.7.3", "\\a1"};
443448
// clang-format off
444449
msg = "here is a string with a small int " + var_strs[0]
445450
+ " and a very large int " + var_strs[1]
446451
+ " and a double " + var_strs[2]
447452
+ " and a weird double " + var_strs[3]
448-
+ " and a str with numbers "
449-
+ var_strs[4] + " and an escape "
453+
+ " and a str with numbers " + var_strs[4]
454+
+ " and a str with a backslash and numbers " + var_strs[5]
455+
+ " and an escape "
450456
+ enum_to_underlying_type(VariablePlaceholder::Escape)
451457
+ " and an int placeholder "
452458
+ enum_to_underlying_type(VariablePlaceholder::Integer)
@@ -530,6 +536,30 @@ TEST_CASE("EncodedVariableInterpreter", "[EncodedVariableInterpreter]") {
530536
search_logtype,
531537
sub_query
532538
));
539+
auto escape_handler = [](std::string_view str) -> std::string {
540+
std::string escaped_string;
541+
for (auto const c : str) {
542+
if ('*' == c || '?' == c
543+
|| enum_to_underlying_type(VariablePlaceholder::Escape) == c
544+
|| enum_to_underlying_type(VariablePlaceholder::Integer) == c
545+
|| enum_to_underlying_type(VariablePlaceholder::Float) == c
546+
|| enum_to_underlying_type(VariablePlaceholder::Dictionary) == c)
547+
{
548+
escaped_string.push_back(enum_to_underlying_type(VariablePlaceholder::Escape));
549+
}
550+
escaped_string.push_back(c);
551+
}
552+
return escaped_string;
553+
};
554+
search_logtype += " and a str with a backslash and numbers ";
555+
REQUIRE(EncodedVariableInterpreter::encode_and_search_dictionary(
556+
escape_handler(var_strs[5]),
557+
var_dict_reader,
558+
false,
559+
search_logtype,
560+
sub_query
561+
));
562+
533563
search_logtype += " and an escape ";
534564
search_logtype += enum_to_underlying_type(VariablePlaceholder::Escape);
535565
search_logtype += enum_to_underlying_type(VariablePlaceholder::Escape);

components/core/tests/test-clp_s-search.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,10 @@ TEST_CASE("clp-s-search", "[clp-s][search]") {
203203
{R"aa(msg: "Msg 1: \"Abc123\"")aa", {1}},
204204
{R"aa(msg: "Msg 2: 'Abc123'")aa", {2}},
205205
{R"aa(msg: "Msg 3: \nAbc123")aa", {3}},
206-
// CLP incorrectly generates no subqueries in Grep::process_raw_query for the following
207-
// query, so we skip it for now.
208-
//{R"aa(msg: "Msg 4: \\Abc123")aa", {4}}
206+
{R"aa(msg: "Msg 4: \\Abc123")aa", {4}},
209207
{R"aa(msg: "Msg 5: \rAbc123")aa", {5}},
210208
{R"aa(msg: "Msg 6: \tAbc123")aa", {6}},
211-
{R"aa(msg: "*Abc123*")aa", {1, 2, 3, 5, 6}},
209+
{R"aa(msg: "*Abc123*")aa", {1, 2, 3, 4, 5, 6}},
212210
{R"aa(arr.b > 1000)aa", {7, 8}},
213211
{R"aa(var_string: *)aa", {9}},
214212
{R"aa(clp_string: *)aa", {9}},

components/core/tests/test-string_utils.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <iostream>
2+
#include <limits>
23

34
#include <boost/foreach.hpp>
45
#include <boost/range/combine.hpp>
@@ -13,6 +14,7 @@ using clp::string_utils::cSingleCharWildcard;
1314
using clp::string_utils::cWildcardEscapeChar;
1415
using clp::string_utils::cZeroOrMoreCharsWildcard;
1516
using clp::string_utils::replace_unescaped_char;
17+
using clp::string_utils::unescape_string;
1618
using clp::string_utils::wildcard_match_unsafe;
1719
using clp::string_utils::wildcard_match_unsafe_case_sensitive;
1820
using std::chrono::duration;
@@ -111,6 +113,29 @@ TEST_CASE("clean_up_wildcard_search_string", "[clean_up_wildcard_search_string]"
111113
REQUIRE(clean_up_wildcard_search_string(str) == "abc");
112114
}
113115

116+
TEST_CASE("unescape_string", "[string_utils][unescape_string]") {
117+
SECTION("Simple string unescaping") {
118+
REQUIRE("*?\\" == unescape_string("\\*\\?\\\\"));
119+
REQUIRE("abcd" == unescape_string("abcd\\"));
120+
}
121+
122+
SECTION("Exhaustive string unescaping") {
123+
std::string unescaped_string;
124+
std::string escaped_string;
125+
char c{std::numeric_limits<char>::min()};
126+
while (true) {
127+
escaped_string.push_back('\\');
128+
escaped_string.push_back(c);
129+
unescaped_string.push_back(c);
130+
if (c == std::numeric_limits<char>::max()) {
131+
break;
132+
}
133+
++c;
134+
}
135+
REQUIRE(unescaped_string == unescape_string(escaped_string));
136+
}
137+
}
138+
114139
SCENARIO("Test case sensitive wild card match in all possible ways", "[wildcard]") {
115140
std::string tameString, wildString;
116141

components/core/tests/test_log_files/test_search.jsonl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{"idx": 1, "msg": "Msg 1: \"Abc123\""}
33
{"idx": 2, "msg": "Msg 2: 'Abc123'"}
44
{"idx": 3, "msg": "Msg 3: \nAbc123"}
5-
{"idx": 4, "skip_msg": "Msg 4: \\Abc123"}
5+
{"idx": 4, "msg": "Msg 4: \\Abc123"}
66
{"idx": 5, "msg": "Msg 5: \rAbc123"}
77
{"idx": 6, "msg": "Msg 6: \tAbc123"}
88
{"idx": 7, "arr": [{"a": 999}, {"b": 1001}]}

components/webui/client/eslint.config.mjs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,12 @@ const EslintConfig = [
3131
"new-cap": [
3232
"error",
3333
{
34+
// TypeBox imports
3435
capIsNewExceptions: [
35-
// TypeBox imports
3636
"Decode",
3737
"Encode",
38-
"Type.Literal",
39-
"Type.Optional",
40-
"Type.Transform",
41-
"Type.Union",
42-
"Value.Parse",
4338
],
39+
capIsNewExceptionPattern: "^(Type|Value)\\.",
4440
},
4541
],
4642
},

0 commit comments

Comments
 (0)