You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "John Wagenleitner (JIRA)" <ji...@apache.org> on 2016/10/28 21:10:59 UTC

[jira] [Created] (GROOVY-7979) JsonSlurper parses a single minus character as a number

John Wagenleitner created GROOVY-7979:
-----------------------------------------

             Summary: JsonSlurper parses a single minus character as a number
                 Key: GROOVY-7979
                 URL: https://issues.apache.org/jira/browse/GROOVY-7979
             Project: Groovy
          Issue Type: Bug
          Components: JSON
    Affects Versions: 2.4.7
            Reporter: John Wagenleitner
            Priority: Minor


A minus sign not followed by some digits should fail parsing but succeeds.  The Character Source parser correctly throws an exception..

{code}
import groovy.json.*
import static groovy.json.JsonParserType.*

println new JsonSlurper().setType(CHAR_BUFFER).parseText('[-]') // [-45]
println new JsonSlurper().setType(INDEX_OVERLAY).parseText('[-]') // [-45]
println new JsonSlurper().setType(LAX).parseText('[-]') // [-45]

println new JsonSlurper().setType(CHARACTER_SOURCE).parseText('[-]') // throws JsonException
{code}

The parsers fail to recognize that no digits are appearing after the minus and end up calculating a value based on the next char value.  For example, the char value of {{]}} is 93 and that from the char value of {{0}} (48) is 45.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)