Groovy
  1. Groovy
  2. GROOVY-5144

JsonSlurper does not handle backslashes at the end of a String

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.8.4
    • Fix Version/s: 1.8.6, 2.0-beta-3
    • Component/s: JSON
    • Labels:
      None
    • Environment:
      Ubuntu Linux 11.10 32-bit,

      OpenJDK Runtime Environment (IcedTea6 1.11pre) (6b23~pre11-0ubuntu1.11.10)
      OpenJDK Server VM (build 20.0-b11, mixed mode)

      Description

      Whenever I try to deserialize a JSON Object with a String that ends with a correctly escaped backslash "
      ", it throws an exception:

      Caught: groovy.json.JsonException: Expected a value on line: 1, column: 25.
      But got an unterminated object.
      groovy.json.JsonException: Expected a value on line: 1, column: 25.
      But got an unterminated object.
      at JsonSlurperBug.run(JsonSlurperBug.groovy:9)

      I've attached a small repro.

      1. JsonSlurperBug.groovy
        0.3 kB
        Gabriel Szlechtman

        Activity

        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        52d 2h 18m 1 Guillaume Delcroix 15/Jan/12 10:43
        Resolved Resolved Closed Closed
        27d 17h 19m 1 Paul King 12/Feb/12 04:03
        Mark Thomas made changes -
        Workflow jira [ 12971444 ] Default workflow, editable Closed status [ 12979175 ]
        Mark Thomas made changes -
        Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
        Mark Thomas made changes -
        Workflow jira [ 12734068 ] Default workflow, editable Closed status [ 12745714 ]
        Mark Thomas made changes -
        Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
        Paul King made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Guillaume Delcroix made changes -
        Fix Version/s 1.8.6 [ 18245 ]
        Resolution Fixed [ 1 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 2.0-beta-3 [ 18244 ]
        Hide
        Guillaume Delcroix added a comment -

        Thanks for the pull request!

        Show
        Guillaume Delcroix added a comment - Thanks for the pull request!
        Guillaume Delcroix made changes -
        Field Original Value New Value
        Assignee Guillaume Laforge [ guillaume ]
        Hide
        John Wagenleitner added a comment -

        Problem appears to be this line in JsonLexer#nextToken that determines when the string is terminated by a quote. Any backslash (current -2) appearing before a quote (current char) causes it to keep reading rather than terminating and returning the token. When it is able to read to the next quote that does not have a preceeding backslash I think it then hangs when the pattern match is applied by possibleTokenType.matching(currentContent.toString()).

        I have opened a pull request (https://github.com/groovy/groovy-core/pull/14) on github for this issue.

        Show
        John Wagenleitner added a comment - Problem appears to be this line in JsonLexer#nextToken that determines when the string is terminated by a quote. Any backslash (current -2) appearing before a quote (current char) causes it to keep reading rather than terminating and returning the token. When it is able to read to the next quote that does not have a preceeding backslash I think it then hangs when the pattern match is applied by possibleTokenType.matching(currentContent.toString()) . I have opened a pull request ( https://github.com/groovy/groovy-core/pull/14 ) on github for this issue.
        Hide
        Ed Norris added a comment - - edited

        This is worse than it appears - if you have an element after the offending escaped backslash, the parseText statement hangs (indefinitely? I've waited 20 minutes)
        works:

        {"InstallLocation":"C:\\WINDOWS\\Microsoft.NET\\Framework\\v3.5","a":"b"}

        throws exception:

        {"InstallLocation":"C:\\WINDOWS\\Microsoft.NET\\Framework\\v3.5\\"}

        hangs:

        {"InstallLocation":"C:\\WINDOWS\\Microsoft.NET\\Framework\\v3.5\\","a":"b"}

        Windows 7 x64, groovy-all-1.8.4, Java 1.6.0.24, IntelliJ Idea 10.5.4

        Show
        Ed Norris added a comment - - edited This is worse than it appears - if you have an element after the offending escaped backslash, the parseText statement hangs (indefinitely? I've waited 20 minutes) works: {"InstallLocation":"C:\\WINDOWS\\Microsoft.NET\\Framework\\v3.5","a":"b"} throws exception: {"InstallLocation":"C:\\WINDOWS\\Microsoft.NET\\Framework\\v3.5\\"} hangs: {"InstallLocation":"C:\\WINDOWS\\Microsoft.NET\\Framework\\v3.5\\","a":"b"} Windows 7 x64, groovy-all-1.8.4, Java 1.6.0.24, IntelliJ Idea 10.5.4
        Gabriel Szlechtman created issue -

          People

          • Assignee:
            Guillaume Delcroix
            Reporter:
            Gabriel Szlechtman
          • Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development