Skip to content

BUG: JsonPointer indexes into strings (RFC 6901 non-compliant) #70

Description

@angela-tarantula

JsonPointer incorrectly treats JSON strings as indexable sequences.

>>>fromjsonpointerimportJsonPointer>>>JsonPointer("/foo/0").resolve({"foo": "should-not-be-indexable"})
's'

Per RFC 6901, reference tokens only apply to objects (member lookup) and arrays (index lookup). Applying /0 to a string should fail, but it returns the first character instead.

This bug has downstream implications as well:

>>>fromjsonpatchimportJsonPointer>>>patch= [{'op': 'test', 'path': '/foo/0', "value": "s"}]
>>>doc= {"foo": "should-not-be-indexable"}
>>>JsonPatch(patch).apply(doc)
{'foo': 'should-not-be-indexable'}
>>>fromjsonpatchimportJsonPointer>>>doc= {"foo": "should-not-be-indexable"}
>>>patch= [{'op': 'copy', 'from': '/foo/0', "path": "/bar"}]
>>>JsonPatch(patch).apply(doc)
{'foo': 'should-not-be-indexable', 'bar': 's'}

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