Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-7979

JsonSlurper parses a single minus character as a number

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.4.7
    • Fix Version/s: 2.4.12
    • Component/s: JSON
    • Labels:
      None

      Description

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

      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
      

      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.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jwagenleitner John Wagenleitner
                Reporter:
                jwagenleitner John Wagenleitner
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: