Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2ea529b

Browse filesBrowse files
committed
test: add regression test for 13557
Fixes: #13557 PR-URL: #13560 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 0df6c0b commit 2ea529b
Copy full SHA for 2ea529b

File tree

Expand file treeCollapse file tree

1 file changed

+44
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+44
-0
lines changed
Open diff view settings
Collapse file
+44Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
'use strict';
2+
3+
// Regression test for https://github.com/nodejs/node/issues/13557
4+
// Tests that multiple subsequent readline instances can re-use an input stream.
5+
6+
const common = require('../common');
7+
const assert = require('assert');
8+
const readline = require('readline');
9+
const { PassThrough } = require('stream');
10+
11+
const input = new PassThrough();
12+
const output = new PassThrough();
13+
14+
const rl1 = readline.createInterface({
15+
input,
16+
output,
17+
terminal: true
18+
});
19+
20+
rl1.on('line', common.mustCall(rl1OnLine));
21+
22+
// Write a line plus the first byte of a UTF-8 multibyte character to make sure
23+
// that it doesn’t get lost when closing the readline instance.
24+
input.write(Buffer.concat([
25+
Buffer.from('foo\n'),
26+
Buffer.from([ 0xe2 ]) // Exactly one third of a ☃ snowman.
27+
]));
28+
29+
function rl1OnLine(line) {
30+
assert.strictEqual(line, 'foo');
31+
rl1.close();
32+
const rl2 = readline.createInterface({
33+
input,
34+
output,
35+
terminal: true
36+
});
37+
38+
rl2.on('line', common.mustCall((line) => {
39+
assert.strictEqual(line, '☃bar');
40+
rl2.close();
41+
}));
42+
input.write(Buffer.from([0x98, 0x83])); // The rest of the ☃ snowman.
43+
input.write('bar\n');
44+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.