diff --git a/CHANGELOG.rst b/CHANGELOG.rst index dc673df4..328ff5d2 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,7 +1,7 @@ Next Release (TBD) ================== -* No changes yet. +* Fix slice projections following an array index. 1.1.0 diff --git a/jmespath/parser.py b/jmespath/parser.py index cc8e804e..4b145a42 100644 --- a/jmespath/parser.py +++ b/jmespath/parser.py @@ -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. diff --git a/tests/compliance/slice.json b/tests/compliance/slice.json index 35947727..677fd841 100644 --- a/tests/compliance/slice.json +++ b/tests/compliance/slice.json @@ -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] + } + ] }]