[ https://issues.apache.org/jira/browse/GROOVY-7476?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14603696#comment-14603696 ]
ASF GitHub Bot commented on GROOVY-7476: ---------------------------------------- GitHub user gvaneyck opened a pull request: https://github.com/apache/incubator-groovy/pull/46 GROOVY-7476 - Fix JSON parsing error when escape character is read at… … the end of the buffer You can merge this pull request into a Git repository by running: $ git pull https://github.com/gvaneyck/incubator-groovy master Alternatively you can review and apply these changes as the patch at: https://github.com/apache/incubator-groovy/pull/46.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #46 ---- commit 5fc4cb6d527cd73578ca2f24572eb95eefde6623 Author: Gvaneyck <gvane...@riotgames.com> Date: 2015-06-26T22:17:49Z GROOVY-7476 - Fix JSON parsing error when escape character is read at the end of the buffer ---- > JsonSlurper sometimes does not parse escaped double quotes on parsing with > JsonParsingUsingCharacterSource > ---------------------------------------------------------------------------------------------------------- > > Key: GROOVY-7476 > URL: https://issues.apache.org/jira/browse/GROOVY-7476 > Project: Groovy > Issue Type: Bug > Components: JSON > Affects Versions: 2.3.11, 2.4.3 > Reporter: Gabriel Van Eyck > Assignee: Guillaume Laforge > Priority: Minor > Labels: contributers-welcome > > This came up when parsing a JSON string that had escaped JSON in it. > E.g. {noformat}{"string": "{\"key\": \"value\"}"}{noformat} > If the escape character used for ReaderCharacterSource.findNextChar is the > last character in the buffer, then "foundEscape" is ignored for the first > character in the recursion call (ReaderCharacterSource:229) and the match > character is not added to the result. > {code} > import groovy.json.internal.ReaderCharacterSource > def testString = '"double\\"quote"' > def expectedString = testString.substring(1, testString.length() - 1) > def escapedQuotePos = testString.indexOf('"', 1) > int quoteChar = (int)'"'.charAt(0) > int backslashChar = (int)'\\'.charAt(0) > ReaderCharacterSource rcs > char[] result > rcs = new ReaderCharacterSource(new StringReader(testString), escapedQuotePos > - 1) > result = rcs.findNextChar(quoteChar, backslashChar) > assert(expectedString == new String(result)) > rcs = new ReaderCharacterSource(new StringReader(testString), escapedQuotePos > + 1) > result = rcs.findNextChar(quoteChar, backslashChar) > assert(expectedString == new String(result)) > // This one fails due to the backslash being the last character in the buffer > rcs = new ReaderCharacterSource(new StringReader(testString), escapedQuotePos) > result = rcs.findNextChar(quoteChar, backslashChar) > assert(expectedString == new String(result)) > {code} -- This message was sent by Atlassian JIRA (v6.3.4#6332)