Fix error when the filtered datum is not iterable
This commit is contained in:
parent
4c667b8643
commit
da3e74d4ff
|
@ -38,6 +38,9 @@ class Filter(jsonpath_rw.JSONPath):
|
|||
return datum
|
||||
|
||||
datum = jsonpath_rw.DatumInContext.wrap(datum)
|
||||
if not isinstance(datum.value, list):
|
||||
return []
|
||||
|
||||
return [jsonpath_rw.DatumInContext(datum.value[i],
|
||||
path=jsonpath_rw.Index(i),
|
||||
context=datum)
|
||||
|
|
|
@ -238,6 +238,17 @@ class TestJsonpath_rw_ext(testscenarios.WithScenarios,
|
|||
target=["cat-bow"]
|
||||
)),
|
||||
|
||||
('bug-#2-correct', dict(
|
||||
string='foo[?(@.baz==1)]',
|
||||
data={'foo': [{'baz': 1}, {'baz': 2}]},
|
||||
target=[{'baz': 1}],
|
||||
)),
|
||||
|
||||
('bug-#2-wrong', dict(
|
||||
string='foo[*][?(@.baz==1)]',
|
||||
data={'foo': [{'baz': 1}, {'baz': 2}]},
|
||||
target=[],
|
||||
)),
|
||||
]
|
||||
|
||||
def test_fields_value(self):
|
||||
|
|
Loading…
Reference in New Issue