diff --git a/rslib/src/search/parser.rs b/rslib/src/search/parser.rs index a450f26f8..d160a5c69 100644 --- a/rslib/src/search/parser.rs +++ b/rslib/src/search/parser.rs @@ -168,6 +168,9 @@ fn group_inner(input: &str) -> IResult<&str, Vec> { if nodes.is_empty() { Err(nom::Err::Error((remaining, nom::error::ErrorKind::Many1))) + } else if matches!(nodes.last().unwrap(), Node::And | Node::Or) { + // no trailing and/or + Err(nom::Err::Failure(("", nom::error::ErrorKind::NoneOf))) } else { // chomp any trailing whitespace let (remaining, _) = whitespace0(remaining)?; @@ -434,6 +437,11 @@ mod test { assert_eq!(parse("")?, vec![Search(SearchNode::WholeCollection)]); assert_eq!(parse(" ")?, vec![Search(SearchNode::WholeCollection)]); + // leading/trailing boolean operators + assert!(parse("foo and").is_err()); + assert!(parse("and foo").is_err()); + assert!(parse("and").is_err()); + // leading/trailing/interspersed whitespace assert_eq!( parse(" t t2 ")?,