Skip to content

Commit

Permalink
Fix PumpReader support for supplementary code points, fixes #658 (#716)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Oct 14, 2021
1 parent 0a35dc7 commit deb7469
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion terminal/src/main/java/org/jline/utils/PumpReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ private InputStream(PumpReader reader, Charset charset) {
this.encoder = charset.newEncoder()
.onUnmappableCharacter(CodingErrorAction.REPLACE)
.onMalformedInput(CodingErrorAction.REPLACE);
this.buffer = ByteBuffer.allocate((int) Math.ceil(encoder.maxBytesPerChar()));
this.buffer = ByteBuffer.allocate((int) Math.ceil(encoder.maxBytesPerChar() * 2));

// No input available after initialization
buffer.limit(0);
Expand Down
6 changes: 3 additions & 3 deletions terminal/src/test/java/org/jline/utils/PumpReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private PumpReader writeInput() {

// Write some input
writer.println("Hello world!");
writer.println("");
writer.println("\uD83D\uDE0A");

return pump;
}
Expand All @@ -37,7 +37,7 @@ public void testReader() throws IOException {
// Read it again
BufferedReader reader = new BufferedReader(pump);
assertEquals("Hello world!", reader.readLine());
assertEquals("", reader.readLine());
assertEquals("\uD83D\uDE0A", reader.readLine());
}

@Test
Expand All @@ -47,7 +47,7 @@ public void testInputStream() throws IOException {
// Read it using an input stream
BufferedReader reader = new BufferedReader(new InputStreamReader(pump.createInputStream(StandardCharsets.UTF_8), StandardCharsets.UTF_8));
assertEquals("Hello world!", reader.readLine());
assertEquals("", reader.readLine());
assertEquals("\uD83D\uDE0A", reader.readLine());
}

}

0 comments on commit deb7469

Please sign in to comment.