다중패스 필터 안되는 문제 수정

This commit is contained in:
freestrings 2020-03-10 23:22:35 +09:00
parent 6f20013076
commit a6f742e3ad
2 changed files with 36 additions and 1 deletions

View File

@ -286,7 +286,26 @@ impl<'a> ExprTerm<'a> {
if ret.is_empty() { if ret.is_empty() {
ExprTerm::Bool(cmp_fn.default()) ExprTerm::Bool(cmp_fn.default())
} else if let Some(rel) = rel { } else if let Some(rel) = rel {
if let ExprTerm::Json(_, _, _) = &other {
ExprTerm::Json(Some(rel.to_vec()), None, ret) ExprTerm::Json(Some(rel.to_vec()), None, ret)
} else {
let mut tmp = Vec::new();
for rel_value in rel {
match rel_value {
Value::Object(map) => {
for map_value in map.values() {
for result_value in &ret {
if map_value.eq(*result_value) {
tmp.push(*rel_value);
}
}
}
}
_ => {}
}
}
ExprTerm::Json(Some(tmp), None, ret)
}
} else { } else {
ExprTerm::Json(None, None, ret) ExprTerm::Json(None, None, ret)
} }

View File

@ -126,6 +126,22 @@ fn filter_parent_exist_child() {
); );
} }
#[test]
fn filter_parent_paths() {
setup();
select_and_then_compare(
"$[?(@.key.subKey == 'subKey2')]",
json!([
{"key": {"seq": 1, "subKey": "subKey1"}},
{"key": {"seq": 2, "subKey": "subKey2"}},
{"key": 42},
{"some": "value"}
]),
json!([{"key": {"seq": 2, "subKey": "subKey2"}}]),
);
}
#[test] #[test]
fn bugs33_exist_in_all() { fn bugs33_exist_in_all() {
setup(); setup();