Skip to content
Permalink
Browse files
8267459: Pasting Unicode characters into JShell does not work.
Reviewed-by: vromero
  • Loading branch information
Jan Lahoda committed Jun 2, 2021
1 parent 9247630 commit de6472c44166e57cd440b7bffcfc876585aca7dd
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
@@ -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();
}
}
@@ -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
@@ -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
});
}
}
@@ -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;
@@ -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);

1 comment on commit de6472c

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on de6472c Jun 2, 2021

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.