Parse spaces in JSONPath logical expressions

This commit is contained in:
Fabrice Reix 2025-11-29 08:47:48 +01:00 committed by hurl-bot
parent 26323ecac0
commit f3a09ebf49
No known key found for this signature in database
GPG Key ID: 1283A2B4A0DCAF8D
1 changed files with 7 additions and 2 deletions

View File

@ -17,7 +17,7 @@
*/
use crate::jsonpath2::ast::expr::{AndExpr, LogicalExpr, NotExpr, OrExpr, TestExpr, TestExprKind};
use crate::jsonpath2::parser::comparison::try_parse as try_comparison;
use crate::jsonpath2::parser::primitives::match_str;
use crate::jsonpath2::parser::primitives::{match_str, skip_whitespace};
use crate::jsonpath2::parser::query::try_filter_query;
use crate::jsonpath2::parser::{ParseError, ParseErrorKind, ParseResult};
use hurl_core::reader::Reader;
@ -30,9 +30,11 @@ pub fn logical_or_expr(reader: &mut Reader) -> ParseResult<LogicalExpr> {
// Parse additional operands separated by "||"
loop {
skip_whitespace(reader);
if !match_str("||", reader) {
break;
}
skip_whitespace(reader);
operands.push(logical_or_expr(reader)?);
}
@ -51,9 +53,11 @@ fn logical_and_expr(reader: &mut Reader) -> ParseResult<LogicalExpr> {
// Parse additional operands separated by "&&"
loop {
skip_whitespace(reader);
if !match_str("&&", reader) {
break;
}
skip_whitespace(reader);
operands.push(basic_expr(reader)?);
}
@ -148,7 +152,7 @@ mod tests {
#[test]
fn test_parse_or_expression() {
let mut reader = Reader::new("@<2||@>4");
let mut reader = Reader::new("@<2 || @>4");
assert_eq!(
logical_or_expr(&mut reader).unwrap(),
LogicalExpr::Or(OrExpr::new(vec![
@ -168,6 +172,7 @@ mod tests {
))
]))
);
assert_eq!(reader.cursor().index, hurl_core::reader::CharPos(10));
}
#[test]