Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-7173

jsonslurper does not unescape Strings (sometimes) on parsing with JsonParsingUsingCharacterSource

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.3.6, 2.4.0-rc-1
    • Fix Version/s: 2.3.10, 2.4.1
    • Component/s: JSON
    • Labels:
      None

      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
       + }
       

        Attachments

        1. ReaderCharacterSourceTest.groovy
          0.9 kB
          Tobias Conrad

          Activity

            People

            • Assignee:
              pschumacher Pascal Schumacher
              Reporter:
              toconex Tobias Conrad
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: