groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Wagenleitner <john.wagenleit...@gmail.com>
Subject Re: GROOVY-7979 and Index Overlay JSON parser behaviour
Date Tue, 16 May 2017 23:40:27 GMT
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 <james@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
>

Mime
View raw message