Skip to content

Null objs #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions jsonpath_rw/jsonpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ class Index(JSONPath):
JSONPath that matches indices of the current datum, or none if not large enough.
Concrete syntax is brackets.

WARNING: If the datum is not long enough, it will not crash but will not match anything.
WARNING: If the datum is None or not long enough, it will not crash but will not match anything.
NOTE: For the concrete syntax of `[*]`, the abstract syntax is a Slice() with no parameters (equiv to `[:]`
"""

Expand All @@ -440,7 +440,7 @@ def __init__(self, index):
def find(self, datum):
datum = DatumInContext.wrap(datum)

if len(datum.value) > self.index:
if datum.value and len(datum.value) > self.index:
return [DatumInContext(datum.value[self.index], path=self, context=datum)]
else:
return []
Expand Down
3 changes: 2 additions & 1 deletion tests/test_jsonpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ def test_index_value(self):
self.check_cases([
('[0]', [42], [42]),
('[5]', [42], []),
('[2]', [34, 65, 29, 59], [29])
('[2]', [34, 65, 29, 59], [29]),
('[0]', None, [])
])

def test_slice_value(self):
Expand Down