You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@groovy.apache.org by James Laverack <ja...@jameslaverack.com> on 2017/05/14 20:02:12 UTC

GROOVY-7979 and Index Overlay JSON parser behaviour

Hi all,

I'm interested in contributing to Groovy development, so I've taken a look
at the bug tracker and taken up GROOVY-7979. Most of this is pretty
straightforward, but I'm having a bit of difficulty with figuring out how
the index overlay parsers (`INDEX_OVERLAY` and `LAX`) should behave.

The ticket seems to imply that like the other parser implementations they
should throw a JsonException when attempting to parse the string "[-]". But
because the index overlay parser doesn't parse the value in the array until
it's called for, simply doing `parser.parseText('[-]')` won't throw an
exception whereas `parser.parseText('[-]')[0]` would. (With the fixes I've
implemented to the number parsing code that fix the other parsers anyway.)

Is it acceptable to have the lax parser behave like this and not throw the
exception until the value is accessed, or should the implementation of
`NumberValue` check for this case when it's created?

Thanks,
James Laverack

Re: GROOVY-7979 and Index Overlay JSON parser behaviour

Posted by John Wagenleitner <jo...@gmail.com>.
Hi James,

My opinion is that it should fail to parse, similar to the following:

----------------
import groovy.json.*

def parser = new JsonSlurper().setType(JsonParserType.INDEX_OVERLAY)

parser.parseText('{"num": 6-}')

//groovy.json.JsonException: unexpected character -
//
//The current character read is '6' with an int value of 54
//unexpected character -
//line number 1
//index number 8
//{"num": 6-}
----------------

It might be possible to check if there's a minus sign found and the from-to
index is 1 in the decodeNumber* methods with affecting performance too much.

John


On Sun, May 14, 2017 at 1:02 PM, James Laverack <ja...@jameslaverack.com>
wrote:

> Hi all,
>
> I'm interested in contributing to Groovy development, so I've taken a look
> at the bug tracker and taken up GROOVY-7979. Most of this is pretty
> straightforward, but I'm having a bit of difficulty with figuring out how
> the index overlay parsers (`INDEX_OVERLAY` and `LAX`) should behave.
>
> The ticket seems to imply that like the other parser implementations they
> should throw a JsonException when attempting to parse the string "[-]". But
> because the index overlay parser doesn't parse the value in the array until
> it's called for, simply doing `parser.parseText('[-]')` won't throw an
> exception whereas `parser.parseText('[-]')[0]` would. (With the fixes I've
> implemented to the number parsing code that fix the other parsers anyway.)
>
> Is it acceptable to have the lax parser behave like this and not throw the
> exception until the value is accessed, or should the implementation of
> `NumberValue` check for this case when it's created?
>
> Thanks,
> James Laverack
>