Skip to content
Closed
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
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Next Release (TBD)
==================

* No changes yet.
* Fix slice projections following an array index.


1.1.0
Expand Down
3 changes: 2 additions & 1 deletion jmespath/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@ def _token_led_lbracket(self, left):
token = self._lookahead_token(0)
if token['type'] in ['number', 'colon']:
right = self._parse_index_expression()
if left['type'] == 'index_expression':
if (left['type'] == 'index_expression' and
right['type'] != 'slice'):
# Optimization: if the left node is an index expr,
# we can avoid creating another node and instead just add
# the right node as a child of the left.
Expand Down
65 changes: 65 additions & 0 deletions tests/compliance/slice.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,69 @@
"result": []
}
]
}, {
"given": {
"foo": [[{"a": 1}, {"a": 2}, {}]],
"bar": [[[1, 2], [3, 4], [5, 6]]],
"baz": [{"a": 1}],
"nulls": [[1, null, 2]]
},
"cases": [
{
"expression": "foo[0][:2].a",
"result": [1, 2]
},
{
"expression": "foo[-1][::-1].a",
"result": [2, 1]
},
{
"expression": "foo[0][:0].a",
"result": []
},
{
"expression": "foo[0][:].b",
"result": []
},
{
"expression": "foo[0][:2]",
"result": [{"a": 1}, {"a": 2}]
},
{
"expression": "foo[0][:2] | [0].a",
"result": 1
},
{
"expression": "bar[0][:2][0]",
"result": [1, 3]
},
{
"expression": "bar[0][0][:1]",
"result": [1]
},
{
"expression": "bar[0][0][:1].a",
"result": []
},
{
"expression": "baz[0][:].a",
"result": null
},
{
"expression": "foo[4][:].a",
"result": null
},
{
"expression": "nulls[0][:]",
"result": [1, 2]
}
]
}, {
"given": [[{"a": 1}, {"a": 2}]],
"cases": [
{
"expression": "[0][:2].a",
"result": [1, 2]
}
]
}]