Skip to content

BUG: JSON Patch operations sometimes treat strings as arrays (RFC 6902 non-compliant) #178

Description

@angela-tarantula

JsonPatch currently allows JSON Patch operations to resolve pointer segments like /0 against JSON strings, effectively indexing into strings and producing characters. This is not compliant with JSON Pointer (RFC 6901) evaluation rules, and therefore causes JSON Patch (RFC 6902) operations to behave incorrectly.

>>> 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'}

Upstream issue.

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