Skip to content

Commit 9854907

Browse files
committed
fix: filter context selector from filter function, closes #8
1 parent 24ff877 commit 9854907

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

jsonpath/parse.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ def __init__(self, *, env: JSONPathEnvironment) -> None:
243243
TOKEN_TRUE: self.parse_boolean,
244244
TOKEN_ROOT: self.parse_root_path,
245245
TOKEN_SELF: self.parse_self_path,
246+
TOKEN_FILTER_CONTEXT: self.parse_filter_context_path,
246247
}
247248

248249
def parse(self, stream: TokenStream) -> Iterable[JSONPathSelector]:

tests/test_filter_context.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""Extra filter context test cases."""
2+
import pytest
3+
4+
from jsonpath import JSONPathEnvironment
5+
6+
7+
@pytest.fixture()
8+
def env() -> JSONPathEnvironment:
9+
return JSONPathEnvironment()
10+
11+
12+
def test_filter_context_selector_in_filter_function(env: JSONPathEnvironment) -> None:
13+
"""Test that we can pass extra filter context to findall."""
14+
rv = env.findall(
15+
"$[?(@.some == length(_.other))]",
16+
{"foo": {"some": 1, "thing": 2}},
17+
filter_context={"other": ["a"]},
18+
)
19+
assert rv == [{"some": 1, "thing": 2}]

0 commit comments

Comments
 (0)