Skip to content

Commit dafca83

Browse files
committed
Add a test and fix some typos
1 parent 0c15a44 commit dafca83

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

jsonpath/env.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class attributes `root_token`, `self_token` and `filter_context_token`.
9999
intersection_token (str): The pattern used as the intersection operator.
100100
Defaults to `"&"`.
101101
key_token (str): The pattern used to identify the current key or index when
102-
filtering a, mapping or sequence. Defaults to `"#"`.
102+
filtering a mapping or sequence. Defaults to `"#"`.
103103
keys_selector_token (str): The pattern used as the "keys" selector. Defaults to
104104
`"~"`.
105105
lexer_class: The lexer to use when tokenizing path strings.

jsonpath/pointer.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,14 @@ def _handle_key_error(self, obj: Any, key: Any, err: Exception) -> object:
140140
# Try a string repr of the index-like item as a mapping key.
141141
return self._getitem(obj, str(key))
142142

143-
# Handle non-standard keys/property selector/pointer.
143+
# Handle non-standard key/property selector/pointer.
144144
#
145-
# For the benefit of `RelativeJSONPointer.to()`, treat keys starting with a `#`
146-
# as a "key pointer". If `key[1:]` is a key in `obj`, return the key.
145+
# For the benefit of `RelativeJSONPointer.to()` and `JSONPathMatch.pointer()`,
146+
# treat keys starting with a `#` or `~` as a "key pointer". If `key[1:]` is a
147+
# key in `obj`, return the key.
147148
#
148-
# Note that is a key with a leading `#` exists in `obj`, it will have been
149+
# Note that if a key with a leading `#`/`~` exists in `obj`, it will have been
149150
# handled by `_getitem`.
150-
#
151-
# TODO: Same goes for `~`
152151
if (
153152
isinstance(key, str)
154153
and isinstance(obj, Mapping)

tests/test_json_pointer.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_resolve_with_default() -> None:
4040
assert pointer.resolve(data, default=None) is None
4141

4242

43-
def test_pointer_index_out_fo_range() -> None:
43+
def test_pointer_index_out_of_range() -> None:
4444
max_plus_one = JSONPointer.max_int_index + 1
4545
min_minus_one = JSONPointer.min_int_index - 1
4646

@@ -309,6 +309,12 @@ def test_non_standard_index_pointer_with_leading_zero() -> None:
309309
JSONPointer("/foo/bar/#09").resolve(data)
310310

311311

312+
def test_non_standard_index_pointer_to_non_array_object() -> None:
313+
data = {"foo": {"bar": True, "#baz": "hello"}}
314+
with pytest.raises(JSONPointerTypeError):
315+
JSONPointer("/foo/bar/#1").resolve(data)
316+
317+
312318
def test_trailing_slash() -> None:
313319
data = {"foo": {"": [1, 2, 3], " ": [4, 5, 6]}}
314320
assert JSONPointer("/foo/").resolve(data) == [1, 2, 3]

0 commit comments

Comments
 (0)