jackson-core icon indicating copy to clipboard operation
jackson-core copied to clipboard

Number parsing should fail for trailing dot (period)

Open cowtowncoder opened this issue 4 years ago • 4 comments

Looks like content such as:

[ 100.300.30 ]

does pass and report number token 100.300, only failing when trying to access to the following token. This should be caught earlier.

cowtowncoder avatar Feb 06 '21 01:02 cowtowncoder

Looks like this affects non-root numeric values -- at root level (where it is not that valuable, alas) existence of separator is checked as expected. Should also check in other contexts but things get much more ... interesting... since there are legitimately more potentially valid characters compared to root level (where only white-space is allowed as separators)

cowtowncoder avatar Feb 11 '21 01:02 cowtowncoder

Why do you think that "100k" should throw an Exception? Wouldn't it be better that it gets a String result instead?

TheSasch avatar Oct 03 '21 18:10 TheSasch

If you mean "document" like:

100k

that should fail not being valid JSON value (and by extension neither JSON document). The default behavior Jackson aims for is to only accept well-formed valid JSON content.

There is then a separate question of optionally allowing deviations; a few cases exist (enabled by JsonReadFeature). In those cases it is also important to define exactly what else would be accepted. You may file an issue to request acceptance for specific additional classes if they are something you would like to see.

cowtowncoder avatar Oct 03 '21 21:10 cowtowncoder

Oh thank you. I did also had a look at the RFC for JSON and didn't know that a String must always have " surrounded. I thought I've seen JSON in the past without it. Like in YML.

I had a look at the Unit Tests you wrote and also found the first possible problem within UTF8StreamJsonProcessor. At the End of _ParsePosNumber you don't stop when there is another char than a Number. (After the if statement where you know that an "e", "E" or "." would get you to a floating number.

One possible solution would be to look if the current char is a whitespace and continue then. If it's not then there must be an error. But this is only a first look in the code and for now I don't know what standard you have to throw exceptions. And also the other positions are still left where that could be a problem. So I did not have a PR for now.

TheSasch avatar Oct 04 '21 06:10 TheSasch