Skip to content

Commit

Permalink
8267459: Pasting Unicode characters into JShell does not work.
Browse files Browse the repository at this point in the history
Reviewed-by: vromero
  • Loading branch information
lahodaj committed Jun 2, 2021
1 parent 9247630 commit de6472c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
Expand Up @@ -214,10 +214,27 @@ public int readBuffered(char[] b) throws IOException {
if (l < 0) {
return l;
} else {
ByteBuffer bytes = ByteBuffer.wrap(buf, 0, l);
ByteBuffer currentBytes;
if (bytes.hasRemaining()) {
int transfer = bytes.remaining();
byte[] newBuf = new byte[l + transfer];
bytes.get(newBuf, 0, transfer);
System.arraycopy(buf, 0, newBuf, transfer, l);
currentBytes = ByteBuffer.wrap(newBuf);
bytes.position(0);
bytes.limit(0);
} else {
currentBytes = ByteBuffer.wrap(buf, 0, l);
}
CharBuffer chars = CharBuffer.wrap(b);
decoder.decode(bytes, chars, false);
decoder.decode(currentBytes, chars, false);
chars.flip();
if (currentBytes.hasRemaining()) {
int pos = bytes.position();
bytes.limit(bytes.limit() + currentBytes.remaining());
bytes.put(currentBytes);
bytes.position(pos);
}
return chars.remaining();
}
}
Expand Down
16 changes: 15 additions & 1 deletion test/langtools/jdk/jshell/PasteAndMeasurementsUITest.java
Expand Up @@ -23,7 +23,7 @@

/**
* @test
* @bug 8182297 8242919
* @bug 8182297 8242919 8267459
* @summary Verify that pasting multi-line snippets works properly.
* @library /tools/lib
* @modules
Expand Down Expand Up @@ -90,4 +90,18 @@ public void testBracketedPaste() throws Exception {
waitOutput(out, "int i;");
});
}

public void testBracketedPasteNonAscii() throws Exception {
Field cons = System.class.getDeclaredField("cons");
cons.setAccessible(true);
Constructor console = Console.class.getDeclaredConstructor();
console.setAccessible(true);
cons.set(null, console.newInstance());
doRunTest((inputSink, out) -> {
inputSink.write(LineReaderImpl.BRACKETED_PASTE_BEGIN +
"int \u010d;" +
LineReaderImpl.BRACKETED_PASTE_END);
waitOutput(out, "int \uffc4\uff8d;"); //UTF-8 encoding of \u010d
});
}
}
3 changes: 2 additions & 1 deletion test/langtools/jdk/jshell/UITesting.java
Expand Up @@ -28,6 +28,7 @@
import java.io.PrintStream;
import java.io.Writer;
import java.lang.reflect.Field;
import java.nio.charset.StandardCharsets;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Locale;
Expand Down Expand Up @@ -98,7 +99,7 @@ protected void doRunTest(Test test) throws Exception {
}
});

Writer inputSink = new OutputStreamWriter(input.createOutput()) {
Writer inputSink = new OutputStreamWriter(input.createOutput(), StandardCharsets.UTF_8) {
@Override
public void write(String str) throws IOException {
super.write(str);
Expand Down

1 comment on commit de6472c

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.