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 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 @@ -89,4 +89,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
});
}
}