You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2021/03/03 19:40:00 UTC

[jira] [Updated] (GROOVY-9954) JsonSlurper LAX parser skips the first character after comments

     [ https://issues.apache.org/jira/browse/GROOVY-9954?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eric Milles updated GROOVY-9954:
--------------------------------
    Fix Version/s: 3.0.8

> JsonSlurper LAX parser skips the first character after comments
> ---------------------------------------------------------------
>
>                 Key: GROOVY-9954
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9954
>             Project: Groovy
>          Issue Type: Bug
>          Components: JSON
>    Affects Versions: 4.0.0-alpha-2
>            Reporter: Yuki Kawata
>            Priority: Minor
>             Fix For: 3.0.8, 4.0.0-alpha-3
>
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> h2. Problem
> JsonSlurper with JsonParseType.LAX skips the first character after comments.
> This can cause unexpected parse results or even failures in some cases.
> h3. Example 1
> h4. Input
> {code:groovy}
> println new JsonSlurper().setType(JsonParserType.LAX).parseText("""
> // comment
> {
>   "flag": true,
>   "flag2": false
> }
> """)
> {code}
> h4. Expected result
> {noformat}
> [flag2:false, flag:true]
> {noformat}
> h4. Actual result
> {noformat}
> flag
> {noformat}
> h3. Example 2
> h4. Input
> {code:groovy}
> println new JsonSlurper().setType(JsonParserType.LAX).parseText("""
> {
>   /* comment */"flag": true,
>   "flag2": false
> }
> """)
> {code}
> h4. Expected result
> {noformat}
> [flag2:false, flag:true]
> {noformat}
> h4. Actual result
> {noformat}
> The current character read is 'f' with an int value of 102
> expecting current character to be ':' but got 'f' with an int value of 102
> line number 4
> index number 35
>   "flag2": false
> ...^
> groovy.json.JsonException: expecting current character to be ':' but got 'f' with an int value of 102
> {noformat}
> h2. Root cause
> JsonParserLax.handleComment() (and handleBashComment()) sets the index of the parsed string to the first character after the comment.
> This index is incremented by the for-loop before checking the next character.
> This can cause some unexpected behaviors if the skipped character is not a whitespace.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)