Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8173807

JShell: control characters should be escaped in String values

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 9
    • 9
    • tools
    • None
    • b156
    • Verified

        jshell> String s = "A!\rB!"
        B!"=> "A!

        jshell> String s = "A!\rFOOOOOOOOOOOOOOOOOO"
        FOOOOOOOOOOOOOOOOOO"

        It seems when printing Strings, \r is treated literally as a carriage
        return signal to the shell, which means the next char in the string
        is printed from the beginning of the current line.

        I'm a bit torn: while it's nice that \n (or whichever is native) is
        printed as a new line, maybe it's best (and least bug-prone) to simply
        escape all control characters?

        jshell> String s = "A!\nFOOOOOOOOOOOOOOOOOO"
        s ==> "A!
        FOOOOOOOOOOOOOOOOOO"

        vs

        jshell> String s = "A!\nFOOOOOOOOOOOOOOOOOO"
        s ==> "A!\nFOOOOOOOOOOOOOOOOOO"

              rfield Robert Field (Inactive)
              rfield Robert Field (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: