Skip to content

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

Description

@angela-tarantula

JsonPointer incorrectly treats JSON strings as indexable sequences.

>>> from jsonpointer import JsonPointer
>>> 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:

>>> from jsonpatch import JsonPointer
>>> patch = [{'op': 'test', 'path': '/foo/0', "value": "s"}]
>>> doc = {"foo": "should-not-be-indexable"}
>>> JsonPatch(patch).apply(doc)
{'foo': 'should-not-be-indexable'}
>>> from jsonpatch import JsonPointer
>>> 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'}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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