Skip to content

Commit 2ea529b

Browse files
committed
test: add regression test for 13557
Fixes: #13557 PR-URL: #13560 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 0df6c0b commit 2ea529b

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

test/parallel/test-readline-reopen.js

+44
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)