Skip to content

An exception is thrown for a valid JsonPointer expression #173

@lordofthejars

Description

@lordofthejars

Json-Patch project leader has noted me that there is a bug on JsonPointer implementation and I have decided to investigate.

Basically if you do something like JsonPointer.compile("/1e0"); it throws a NumberFormatExpcetion which is not true. This is because this piece of code:

private final static int _parseInt(String str)
    {
        final int len = str.length();
        if (len == 0) {
            return -1;
        }
        for (int i = 0; i < len; ++i) {
            char c = str.charAt(i++);
            if (c > '9' || c < '0') {
                return -1;
            }
        }
        // for now, we'll assume 32-bit indexes are fine
        return NumberInput.parseInt(str);
    }

When they found a number it interprets the segment as integer but in reality it should be the whole expression. For this reason I think that the condition should be changed to the inverse condition (if it doesn't found any char then it is a number.

If you want I can send you a PR as well.

Alex.

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