-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix: '@text:prefix*' matching for fields. #4868
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
Changes from 2 commits
89ab106
1d48ff8
d4dec97
876f121
bec2045
e63b54d
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 |
---|---|---|
|
@@ -28,14 +28,14 @@ | |
|
||
Parser::symbol_type make_StringLit(string_view src, const Parser::location_type& loc); | ||
Parser::symbol_type make_TagVal(string_view src, const Parser::location_type& loc); | ||
Parser::symbol_type make_TagPrefix(string_view src, const Parser::location_type& loc); | ||
%} | ||
|
||
blank [ \t\r] | ||
dq \" | ||
sq \' | ||
esc_chars ['"\?\\abfnrtv] | ||
esc_seq \\{esc_chars} | ||
term_char [_]|\w | ||
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. why did you remove this? 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. Because \w has [ _ ] as part of its rule. |
||
term_char \w | ||
tag_val_char {term_char}|\\[,.<>{}\[\]\\\"\':;!@#$%^&*()\-+=~\/ ] | ||
|
||
|
||
|
@@ -77,6 +77,7 @@ tag_val_char {term_char}|\\[,.<>{}\[\]\\\"\':;!@#$%^&*()\-+=~\/ ] | |
{term_char}+"*" return Parser::make_PREFIX(str(), loc()); | ||
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. we have now two times + "*" 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. Fixed. |
||
|
||
{term_char}+ return Parser::make_TERM(str(), loc()); | ||
{tag_val_char}+"*" return make_TagPrefix(str(), loc()); | ||
{tag_val_char}+ return make_TagVal(str(), loc()); | ||
|
||
<<EOF>> return Parser::make_YYEOF(loc()); | ||
|
@@ -108,3 +109,25 @@ Parser::symbol_type make_TagVal(string_view src, const Parser::location_type& lo | |
|
||
return Parser::make_TAG_VAL(res, loc); | ||
} | ||
|
||
Parser::symbol_type make_TagPrefix(string_view src, const Parser::location_type& loc) { | ||
string res; | ||
res.reserve(src.size()); | ||
|
||
bool escaped = false; | ||
size_t len = src.size() - 1; // Exclude the '*' at the end | ||
for (size_t i = 0; i < len; ++i) { | ||
if (escaped) { | ||
escaped = false; | ||
} else if (src[i] == '\\') { | ||
escaped = true; | ||
continue; | ||
} | ||
res.push_back(src[i]); | ||
} | ||
|
||
// Add '*' back to make it a prefix | ||
res.push_back('*'); | ||
|
||
return Parser::make_PREFIX(res, loc); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,6 +191,36 @@ TEST_F(SearchParserTest, Scanner) { | |
NEXT_EQ(TOK_DOUBLE, string, "33.3"); | ||
} | ||
|
||
TEST_F(SearchParserTest, EscapedTagPrefixes) { | ||
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. We need also add tests for that to the search_family_test 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. Fixed. |
||
SetInput("@name:{escape\\-err*}"); | ||
NEXT_EQ(TOK_FIELD, string, "@name"); | ||
NEXT_TOK(TOK_COLON); | ||
NEXT_TOK(TOK_LCURLBR); | ||
NEXT_EQ(TOK_PREFIX, string, "escape-err*"); | ||
NEXT_TOK(TOK_RCURLBR); | ||
|
||
SetInput("@name:{escape\\+pre*}"); | ||
NEXT_EQ(TOK_FIELD, string, "@name"); | ||
NEXT_TOK(TOK_COLON); | ||
NEXT_TOK(TOK_LCURLBR); | ||
NEXT_EQ(TOK_PREFIX, string, "escape+pre*"); | ||
NEXT_TOK(TOK_RCURLBR); | ||
|
||
SetInput("@name:{escape\\.pre*}"); | ||
NEXT_EQ(TOK_FIELD, string, "@name"); | ||
NEXT_TOK(TOK_COLON); | ||
NEXT_TOK(TOK_LCURLBR); | ||
NEXT_EQ(TOK_PREFIX, string, "escape.pre*"); | ||
NEXT_TOK(TOK_RCURLBR); | ||
|
||
SetInput("@name:{complex\\-escape\\+with\\.many\\*chars*}"); | ||
NEXT_EQ(TOK_FIELD, string, "@name"); | ||
NEXT_TOK(TOK_COLON); | ||
NEXT_TOK(TOK_LCURLBR); | ||
NEXT_EQ(TOK_PREFIX, string, "complex-escape+with.many*chars*"); | ||
NEXT_TOK(TOK_RCURLBR); | ||
} | ||
|
||
TEST_F(SearchParserTest, Parse) { | ||
EXPECT_EQ(0, Parse(" foo bar (baz) ")); | ||
EXPECT_EQ(0, Parse(" -(foo) @foo:bar @ss:[1 2]")); | ||
|
@@ -200,6 +230,8 @@ TEST_F(SearchParserTest, Parse) { | |
EXPECT_EQ(0, Parse("@foo:{1|2.0|4|3.0}")); | ||
EXPECT_EQ(0, Parse("@foo:{1|hello|3.0|world|4}")); | ||
|
||
EXPECT_EQ(0, Parse("@name:{escape\\-err*}")); | ||
|
||
EXPECT_EQ(1, Parse(" -(foo ")); | ||
EXPECT_EQ(1, Parse(" foo:bar ")); | ||
EXPECT_EQ(1, Parse(" @foo:@bar ")); | ||
|
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.
and this?
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.
This rule is useless.
There is no place where it is used.