Uploaded image for project: 'Commons Text'
  1. Commons Text
  2. TEXT-118

JSON escaping incorrect for the delete control character

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.2
    • Fix Version/s: None
    • Labels:
      None
    • Environment:
      JDK8u162, Mac OS X 13.something.

      Description

      Here's a simple unit test. The assertion about backspace succeeds. The assertion about the delete character fails. Instead, the delete character shows up in the escaped text. This violates the JSON spec, which forbids "control characters" in strings.

      @Test
      public void testDeleteCharacter() {
        String backspaceString = "Backspace: \b";
        String deleteString = "Delete: \u007F";
        assertEquals("Backspace: \\b", StringEscapeUtils.escapeJson(backspaceString));
        assertEquals("Delete: \\u007F", StringEscapeUtils.escapeJson(deleteString));
      }
      

       

      The JSON spec doesn't have a specific escape for a delete character, but it does explicitly exclude control characters from passing through. I'd recommend behavior as in the above unit test.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                chtompki Rob Tompkins
                Reporter:
                dwallach Dan Wallach
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: