stefankoegl / python-json-pointer

Resolve JSON Pointers in Python
https://python-json-pointer.readthedocs.org/
Other
140 stars 43 forks source link

jsonpointer should not expect pointers to be urlencoded #22

Closed stefankoegl closed 7 years ago

stefankoegl commented 7 years ago

As pointed out by @mithrandi in stefankoegl/python-json-patch#63:

The first problem is that jsonpointer expects pointers to be urlencoded, which I don't think is correct (my reading of the RFC is that urlencoding should only be used when the pointer is part of a URL, so nothing special to JSON pointer itself).

My response within the referenced issue

[...] the failing example should be

>>> import jsonpointer
>>> obj = {'a b': 1}
>>> jsonpointer.resolve_pointer(obj, '/a%20b')
1

Instead this should give an error because there is no member a%20b.

It seems that I added the unquoting (currently line 145) already in the very first commit. Initially the [RFC draft|https://tools.ietf.org/html/draft-pbryan-zyp-json-pointer-00] did contain

Property names SHOULD be URI encoded per [RFC2396]. In particular, any "/" character in a property name MUST be encoded as "%2F" to avoid being interpreted as a property reference token separator.

but this was removed before the final RFC, and is thus no longer correct.

anentropic commented 4 years ago

I wondered about this when reading the docs: https://python-json-pointer.readthedocs.io/en/latest/tutorial.html

>>> from jsonpointer import resolve_pointer
>>> obj = {"foo": {"anArray": [ {"prop": 44}], "another prop": {"baz": "A string" }}}

>>> resolve_pointer(obj, '/foo/another%20prop') == obj['foo']['another prop']
True

It seems like this was fixed and urlencoding is not required, do the docs need updating?