Skip to content

jsonpointer will not work with unicode keys in python 2.7 #18

@maxsmythe

Description

@maxsmythe

It looks like jsonpointer will not work with unicode keys, both of the following code snippets fail:

data = {u'\xee': u'\xee'}
jsonpatch.make_patch({}, data)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/sendhub/scratch/contacts_v2_scratch/venv/local/lib/python2.7/site-packages/jsonpatch.py", line 171, in make_patch
    return JsonPatch.from_diff(src, dst)
  File "/opt/sendhub/scratch/contacts_v2_scratch/venv/local/lib/python2.7/site-packages/jsonpatch.py", line 322, in from_diff
    return cls(list(compare_values([], src, dst)))
  File "/opt/sendhub/scratch/contacts_v2_scratch/venv/local/lib/python2.7/site-packages/jsonpatch.py", line 293, in compare_values
    for operation in compare_dicts(path, value, other):
  File "/opt/sendhub/scratch/contacts_v2_scratch/venv/local/lib/python2.7/site-packages/jsonpatch.py", line 314, in compare_dicts
    ptr = JsonPointer.from_parts(path + [key])
  File "/opt/sendhub/scratch/contacts_v2_scratch/venv/local/lib/python2.7/site-packages/jsonpointer.py", line 291, in from_parts
    parts = [str(part) for part in parts]
UnicodeEncodeError: 'ascii' codec can't encode character u'\xee' in position 0: ordinal not in range(128)
data2 = {u'\xee'.encode('utf-8'): u'\xee'.encode('utf-8')}
jsonpatch.make_patch({}, data2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/sendhub/scratch/contacts_v2_scratch/venv/local/lib/python2.7/site-packages/jsonpatch.py", line 171, in make_patch
    return JsonPatch.from_diff(src, dst)
  File "/opt/sendhub/scratch/contacts_v2_scratch/venv/local/lib/python2.7/site-packages/jsonpatch.py", line 322, in from_diff
    return cls(list(compare_values([], src, dst)))
  File "/opt/sendhub/scratch/contacts_v2_scratch/venv/local/lib/python2.7/site-packages/jsonpatch.py", line 293, in compare_values
    for operation in compare_dicts(path, value, other):
  File "/opt/sendhub/scratch/contacts_v2_scratch/venv/local/lib/python2.7/site-packages/jsonpatch.py", line 314, in compare_dicts
    ptr = JsonPointer.from_parts(path + [key])
  File "/opt/sendhub/scratch/contacts_v2_scratch/venv/local/lib/python2.7/site-packages/jsonpointer.py", line 292, in from_parts
    parts = [part.replace('~', '~0') for part in parts]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions