Description
Depending on the position of the escape-character JsonParsingUsingCharacterSource.class does not recognize that the string has an escape. To raise this issue the ReaderCharacterSource.findNextChar() must be invoke recursive and the escape-character is not found in last invocation.
public void findNextCharWithRecursionHadEscape() { char[] control = '"\\'.toCharArray() // create ReaderCharacterSource with a very small buffer, // findNextChar must be invoked recursive // use a string where escape-character is in last invokation ReaderCharacterSource cs = new ReaderCharacterSource(new StringReader('"value\\u0026"'),6) cs.findNextChar((int)control[0],(int)control[1]) // this works assertTrue(cs.hadEscape()) // use a string where escape-character is in first invokation cs = new ReaderCharacterSource(new StringReader('"\\u0026value"'),6) cs.findNextChar((int)control[0],(int)control[1]) // this fail assertTrue("ReaderCharacterSource should have detect escape in sequence", cs.hadEscape()) }
ReaderCharacterSource must keep its property foundEscape if it was true on recursive findNextChar() calls.
groovy.json.internal.ReaderCharacterSource.java-line 231
+ boolean hasAlreadyFoundEscape = foundEscape; char results2[] = findNextChar(match, esc); + if(hasAlreadyFoundEscape){ + foundEscape = true; //restore foundEscapeState + }