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

JsonSlurper parses a single minus character as a number

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.4.7
    • 2.4.12
    • JSON
    • 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

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

              Dates

                Created:
                Updated:
                Resolved: