Skip to content
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

8267459: Pasting Unicode characters into JShell does not work. #4128

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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);