Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An exception is thrown for a valid JsonPointer expression #173

Closed
lordofthejars opened this issue Dec 6, 2014 · 1 comment
Closed

An exception is thrown for a valid JsonPointer expression #173

lordofthejars opened this issue Dec 6, 2014 · 1 comment

Comments

@lordofthejars
Copy link

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.

@cowtowncoder
Copy link
Member

Heh. Have a look at that code again -- there is a bug, but not what you think.

I'll fix this.

cowtowncoder added a commit that referenced this issue Dec 7, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants