From 89da67e08216922a2e8bdb8304debb689c12d454 Mon Sep 17 00:00:00 2001 From: Ryan Chou <88779759+ryanchou1994@users.noreply.github.com> Date: Mon, 21 Sep 2026 11:07:16 +0800 Subject: [PATCH] Fix nested object wildcard projections --- jmespath/parser.py | 2 +- tests/compliance/wildcard.json | 83 ++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) diff --git a/jmespath/parser.py b/jmespath/parser.py index cc8e804e..52dcc220 100644 --- a/jmespath/parser.py +++ b/jmespath/parser.py @@ -266,7 +266,7 @@ def _token_led_dot(self, left): # We're creating a projection. self._advance() right = self._parse_projection_rhs( - self.BINDING_POWER['dot']) + self.BINDING_POWER['star']) return ast.value_projection(left, right) def _token_led_pipe(self, left): diff --git a/tests/compliance/wildcard.json b/tests/compliance/wildcard.json index 3bcec302..aec6eafe 100644 --- a/tests/compliance/wildcard.json +++ b/tests/compliance/wildcard.json @@ -456,5 +456,88 @@ "result": [0, 0] } ] +}, +{ + "given": { + "foo": { + "": {"bar": {"baz": 123}}, + "regular": {"bar": {"baz": 123}}, + "missing": {}, + "nullvalue": {"bar": null} + } + }, + "cases": [ + { + "expression": "foo.*.bar.*", + "result": [[123], [123]] + }, + { + "expression": "foo.*.bar.* | [0]", + "result": [123] + }, + { + "expression": "foo.*.bar.*[]", + "result": [123, 123] + }, + { + "expression": "foo.*.bar | *", + "result": null + }, + { + "expression": "foo.*.bar.* || `false`", + "result": [[123], [123]] + } + ] +}, +{ + "given": { + "foo": { + "first": {"bar": {"second": {"baz": {"value": 123}}}} + } + }, + "cases": [ + { + "expression": "foo.*.bar.second.baz.value", + "result": [123] + }, + { + "expression": "foo.*.bar.*.baz.*", + "result": [[[123]]] + } + ] +}, +{ + "given": { + "foo": { + "first": { + "bar": [{"baz": {"value": 123}}, {"baz": {"value": 456}}] + } + } + }, + "cases": [ + { + "expression": "foo.*.bar[*].baz.*", + "result": [[[123], [456]]] + }, + { + "expression": "foo.*.bar[*].baz.* | [0]", + "result": [[123], [456]] + }, + { + "expression": "foo.*.bar[?baz].baz.*", + "result": [[[123], [456]]] + } + ] +}, +{ + "given": { + "foo": [{"bar": {"first": {"baz": {"value": 123}}}}] + }, + "cases": [ + { + "expression": "foo[*].bar.*.baz.*", + "result": [[[123]]] + } + ] } ]