Fix error when the filtered datum is not iterable

This commit is contained in:
Mehdi Abaakouk 2015-12-08 12:36:29 +01:00
parent 4c667b8643
commit da3e74d4ff
2 changed files with 14 additions and 0 deletions

View File

@ -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)

View File

@ -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):