[ https://issues.apache.org/jira/browse/GROOVY-7476?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Gabriel Van Eyck updated GROOVY-7476: ------------------------------------- Description: 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" status is not passed onto 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)'"'.toCharArray()[0] int backslashChar = (int)'\\'.toCharArray()[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} was: This came up when parsing a JSON string that had escaped JSON in it. E.g. {"string": "{\"key\": \"value\"}"} If the escape character used for ReaderCharacterSource.findNextChar is the last character in the buffer, then "foundEscape" status is not passed onto 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)'"'.toCharArray()[0] int backslashChar = (int)'\\'.toCharArray()[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} > JsonSlurper does not parse escaped double quotes (sometimes) 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 > > 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" status is not passed onto > 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)'"'.toCharArray()[0] > int backslashChar = (int)'\\'.toCharArray()[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)