Skip to content

JsonPathParser seems to wrongly parse unescaped reference-token if its starts with a number #61

Closed
@laurent-gougeon

Description

@laurent-gougeon

Hello,

First of all, I want to thank you for sharing this fork !

In the context of evaluating this fork as a replacement of unmaintained original https://github.com/java-json-tools/json-patch, I think I found an issue in the JsonPathParser

Version used: 2.0.1

simple test code :

    String inputToPatch = "{\"5gStringToMove\":\"exists\"}";

    JsonPatchOperation operation = new MoveOperation("/5gStringToMove", "/5gStringMoved");

    var patch = new JsonPatch(List.of(operation));
    JsonNode objToBePatched = JsonLoader.fromString(inputToPatch);
    JsonNode result = null;
    try
    {
        result = patch.apply(objToBePatched);
    } catch (JsonPatchException e)
    {
        TRACER.fatal(e.getMessage(), e);
        Assertions.fail(e);
    }

The attribute name and JsonPointer towards the attribute is valid as per RFC 6901
Such attribute names are quite frequent in 3GPP standards for example.

But the lib fails in converting the JsonPointer to Json Path :

com.gravity9.jsonpatch.JsonPatchException: Filter: [5]['gStringToMove'] can only be applied to arrays. Current context is: {"5gStringToMove":"exists"}
at com.gravity9.jsonpatch.JsonPatchOperation.apply(JsonPatchOperation.java:124) ~[json-patch-path-2.0.1.jar:?]
at com.gravity9.jsonpatch.JsonPatch.apply(JsonPatch.java:144) ~[json-patch-path-2.0.1.jar:?]
at com.my.example.test.testMoveElementSimple(Test.java:368) ~[test-classes/:?]

The parser considered the number as an array index while it's not even a number, then it split to next char and consider another attribue name.

The issue is more or less here:
https://github.com/gravity9-tech/json-patch-path/blob/master/src/main/java/com/gravity9/jsonpatch/JsonPathParser.java#L7
and here
https://github.com/gravity9-tech/json-patch-path/blob/master/src/main/java/com/gravity9/jsonpatch/JsonPathParser.java#L27

Not sure how to fix this, though...

Original https://github.com/java-json-tools/json-patch was able to patch the same data.

Rgds
Laurent

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions