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

JsonSlurper LAX parser with invalid number

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.4.5
    • Fix Version/s: 2.4.6
    • Component/s: JSON
    • Labels:
      None
    • Environment:
      DISTRIB_ID=Ubuntu
      DISTRIB_RELEASE=14.10
      DISTRIB_CODENAME=utopic
      DISTRIB_DESCRIPTION="Ubuntu 14.10"
      Linux 3.16.0-44-generic x86_64

      Description

      The JsonSlurper LAX parser parses an invalid number incorrectly:

      Example.java
      import groovy.json.*
      
      def obj = new JsonSlurper().setType(JsonParserType.LAX).parseText('{ "num": 1a}')
      println "1a: num = ${obj.num}"
      println "1a: type is " + obj.num.class.name
      
      obj = new JsonSlurper().setType(JsonParserType.LAX).parseText('{ "num": 1A}')
      println "1A: num = ${obj.num}"
      println "1A: type is " + obj.num.class.name
      

      produces:
      1a: num = 59
      1a: type is java.lang.Integer
      1A: num = 27
      1A: type is java.lang.Integer

      It seems like the parser should fail this as an invalid number, though one could argue the LAX parser could interpret it as hex 1a, but neither is being done. Valid numbers are of course parsed correctly.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              reddierocket Alan Hengle
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: