Skip to content

Commit 4fb8c8a

Browse files
committed
test: test cases for surrogate to usv string
Added test cases to check surrogate code points to usv string conversion in stream consumers and text decoder Fixes: nodejs#39804
1 parent 37ab7b0 commit 4fb8c8a

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

test/parallel/test-stream-consumers.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const {
1313
} = require('stream/consumers');
1414

1515
const {
16+
Readable,
1617
PassThrough
1718
} = require('stream');
1819

@@ -74,15 +75,16 @@ const kArrayBuffer =
7475
}
7576

7677
{
77-
const passthrough = new PassThrough();
78+
const readable = new Readable({
79+
read() {}
80+
});
7881

79-
text(passthrough).then(common.mustCall(async (str) => {
80-
assert.strictEqual(str.length, 11);
81-
assert.deepStrictEqual(str, 'hellothere\ufffd');
82-
}));
82+
text(readable).then((data) => {
83+
assert.deepStrictEqual(data, 'foo\ufffd\ufffd\ufffd');
84+
});
8385

84-
passthrough.write('hello');
85-
setTimeout(() => passthrough.end('there\ud801'), 10);
86+
readable.push(new Uint8Array([0x66, 0x6f, 0x6f, 0xed, 0xa0, 0x80]));
87+
readable.push(null);
8688
}
8789

8890
{

test/parallel/test-whatwg-encoding-custom-textdecoder.js

+2-9
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,7 @@ if (common.hasIntl) {
195195
// Test TextDecoder for surrogate code points
196196
{
197197
const decoder = new TextDecoder();
198-
const chunk = Buffer.from([0x66, 0x6f, 0x6f, 0xed, 0xa0, 0x80]);
198+
const chunk = new Uint8Array([0x66, 0x6f, 0x6f, 0xed]);
199199
const str = decoder.decode(chunk);
200-
assert.strictEqual(str, 'foo\ufffd\ufffd\ufffd');
201-
}
202-
203-
{
204-
const decoder = new TextDecoder();
205-
const chunk = Buffer.from('\ud807');
206-
const str = decoder.decode(chunk);
207-
assert.strictEqual(str, '\ufffd');
200+
assert.strictEqual(str, 'foo\ufffd');
208201
}

0 commit comments

Comments
 (0)