Skip to content

Commit 0071432

Browse files
Merge pull request #2960 from Darkheir/fix/query_grammar_boost_and_escape
fix(query-grammar): Fix issues on boosted and regex queries
2 parents 799f7b4 + 7fd1dbe commit 0071432

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

query-grammar/src/query_grammar.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,9 @@ fn exists(inp: &str) -> IResult<&str, UserInputLeaf> {
327327
peek(alt((
328328
value(
329329
"",
330-
satisfy(|c: char| c.is_whitespace() || ESCAPE_IN_WORD.contains(&c)),
330+
satisfy(|c: char| {
331+
c.is_whitespace() || (ESCAPE_IN_WORD.contains(&c) && c != '\\')
332+
}),
331333
),
332334
eof,
333335
))),
@@ -345,7 +347,9 @@ fn exists_precond(inp: &str) -> IResult<&str, (), ()> {
345347
peek(alt((
346348
value(
347349
"",
348-
satisfy(|c: char| c.is_whitespace() || ESCAPE_IN_WORD.contains(&c)),
350+
satisfy(|c: char| {
351+
c.is_whitespace() || (ESCAPE_IN_WORD.contains(&c) && c != '\\')
352+
}),
349353
),
350354
eof,
351355
))), // we need to check this isn't a wildcard query
@@ -707,6 +711,7 @@ fn regex(inp: &str) -> IResult<&str, UserInputLeaf> {
707711
peek(alt((
708712
value((), multispace1),
709713
value((), char(')')),
714+
value((), char('^')),
710715
value((), eof),
711716
))),
712717
),
@@ -728,9 +733,10 @@ fn regex_infallible(inp: &str) -> JResult<&str, UserInputLeaf> {
728733
peek(alt((
729734
value((), multispace1),
730735
value((), char(')')),
736+
value((), char('^')),
731737
value((), eof),
732738
))),
733-
"expected whitespace, closing parenthesis, or end of input",
739+
"expected whitespace, closing parenthesis, boost, or end of input",
734740
),
735741
)(inp)
736742
{
@@ -773,6 +779,10 @@ fn leaf(inp: &str) -> IResult<&str, UserInputAst> {
773779
value((), multispace1),
774780
value((), char(')')),
775781
value((), eof),
782+
value(
783+
(),
784+
satisfy(|c: char| ESCAPE_IN_WORD.contains(&c) && c != '\\'),
785+
),
776786
))),
777787
),
778788
|_| UserInputAst::from(UserInputLeaf::All),
@@ -805,6 +815,10 @@ fn leaf_infallible(inp: &str) -> JResult<&str, Option<UserInputAst>> {
805815
value((), multispace1),
806816
value((), char(')')),
807817
value((), eof),
818+
value(
819+
(),
820+
satisfy(|c: char| ESCAPE_IN_WORD.contains(&c) && c != '\\'),
821+
),
808822
))),
809823
),
810824
),
@@ -1751,6 +1765,8 @@ mod test {
17511765
test_parse_query_to_ast_helper("*", "*");
17521766
test_parse_query_to_ast_helper("(*)", "*");
17531767
test_parse_query_to_ast_helper("(* )", "*");
1768+
// All query with boost
1769+
test_parse_query_to_ast_helper("*^2", "(*)^2");
17541770
}
17551771

17561772
#[test]
@@ -1813,6 +1829,7 @@ mod test {
18131829
test_parse_query_to_ast_helper("a:b*", "\"a\":b*");
18141830
test_parse_query_to_ast_helper("a:*b", "\"a\":*b");
18151831
test_parse_query_to_ast_helper(r#"a:*def*"#, "\"a\":*def*");
1832+
test_parse_query_to_ast_helper("a:*\\:foo", "\"a\":*:foo");
18161833
}
18171834

18181835
#[test]
@@ -1877,6 +1894,8 @@ mod test {
18771894
},
18781895
_ => panic!("Expected a leaf"),
18791896
}
1897+
// Regex followed by `^boost`
1898+
test_parse_query_to_ast_helper(r#"foo:/bar/^2"#, r#"("foo":/bar/)^2"#);
18801899
}
18811900

18821901
#[test]

0 commit comments

Comments
 (0)