-
Notifications
You must be signed in to change notification settings - Fork 5.8k
8356165: System.in in jshell replace supplementary characters with ?? #25079
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
👋 Welcome back jlahoda! A progress list of the required criteria for merging this PR into |
❗ This change is not yet ready to be integrated. |
@@ -977,7 +977,15 @@ public void perform(LineReaderImpl in) throws IOException { | |||
public synchronized int readUserInput() throws IOException { | |||
if (pendingBytes == null || pendingBytes.length <= pendingBytesPointer) { | |||
char userChar = readUserInputChar(); | |||
pendingBytes = String.valueOf(userChar).getBytes(); | |||
StringBuilder dataToConvert = new StringBuilder(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps, add here the comment from the PR description for readers from the future:
[...] when the current character is a high surrogate, peek at the next character, and if it is a low surrogate, convert both the high and low surrogates to bytes together.
The (internal) API used in the implementation doesn't express that on first sight.
if (pendingLine.length() > pendingLinePointer && | ||
Character.isLowSurrogate(pendingLine.charAt(pendingLinePointer))) { | ||
dataToConvert.append(readUserInputChar()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about combining readUserInputChar()
and (only when not surrogate pair but just isolated code unit) pendingLinePointer--
?
pendingLinePointer--
will be unlikely to be happen for normal inputs other than penetration tests.
inputSink.write("new String(System.in.readNBytes(4))\n\uD83D\uDE03\n"); | ||
waitOutput(out, "\"\uD83D\uDE03\""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the following is robuster:
- inputSink.write("new String(System.in.readNBytes(4))\n\uD83D\uDE03\n");
- waitOutput(out, "\"\uD83D\uDE03\"");
+ inputSink.write("new String(System.in.readNBytes(5))\n\uD83D\uDE031\n");
+ waitOutput(out, "\"\uD83D\uDE031\"");
When reading from
System.in
in a JShell snippet, JShell first reads the whole line (getting aString
), and then converts this characters from thisString
to bytes on demand. But, it does not convert multi-surrogate code points correctly, it tries to convert each surrogate separately, which cannot work.The proposal herein is to, when the current character is a high surrogate, peek at the next character, and if it is a low surrogate, convert both the high and low surrogates to bytes together.
Progress
Issue
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/25079/head:pull/25079
$ git checkout pull/25079
Update a local copy of the PR:
$ git checkout pull/25079
$ git pull https://git.openjdk.org/jdk.git pull/25079/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 25079
View PR using the GUI difftool:
$ git pr show -t 25079
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/25079.diff
Using Webrev
Link to Webrev Comment