From 4fb8c8ad110652d3169b3d0272df5550576e383c Mon Sep 17 00:00:00 2001 From: git-srinivas Date: Fri, 22 Oct 2021 01:08:07 +0530 Subject: [PATCH] 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: https://github.com/nodejs/node/issues/39804 --- test/parallel/test-stream-consumers.js | 16 +++++++++------- .../test-whatwg-encoding-custom-textdecoder.js | 11 ++--------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/test/parallel/test-stream-consumers.js b/test/parallel/test-stream-consumers.js index 628c35a793596b..aba1864565d61a 100644 --- a/test/parallel/test-stream-consumers.js +++ b/test/parallel/test-stream-consumers.js @@ -13,6 +13,7 @@ const { } = require('stream/consumers'); const { + Readable, PassThrough } = require('stream'); @@ -74,15 +75,16 @@ const kArrayBuffer = } { - const passthrough = new PassThrough(); + const readable = new Readable({ + read() {} + }); - text(passthrough).then(common.mustCall(async (str) => { - assert.strictEqual(str.length, 11); - assert.deepStrictEqual(str, 'hellothere\ufffd'); - })); + text(readable).then((data) => { + assert.deepStrictEqual(data, 'foo\ufffd\ufffd\ufffd'); + }); - passthrough.write('hello'); - setTimeout(() => passthrough.end('there\ud801'), 10); + readable.push(new Uint8Array([0x66, 0x6f, 0x6f, 0xed, 0xa0, 0x80])); + readable.push(null); } { diff --git a/test/parallel/test-whatwg-encoding-custom-textdecoder.js b/test/parallel/test-whatwg-encoding-custom-textdecoder.js index 29a7c8c9d89d0e..e65c424619d52a 100644 --- a/test/parallel/test-whatwg-encoding-custom-textdecoder.js +++ b/test/parallel/test-whatwg-encoding-custom-textdecoder.js @@ -195,14 +195,7 @@ if (common.hasIntl) { // Test TextDecoder for surrogate code points { const decoder = new TextDecoder(); - const chunk = Buffer.from([0x66, 0x6f, 0x6f, 0xed, 0xa0, 0x80]); + const chunk = new Uint8Array([0x66, 0x6f, 0x6f, 0xed]); const str = decoder.decode(chunk); - assert.strictEqual(str, 'foo\ufffd\ufffd\ufffd'); -} - -{ - const decoder = new TextDecoder(); - const chunk = Buffer.from('\ud807'); - const str = decoder.decode(chunk); - assert.strictEqual(str, '\ufffd'); + assert.strictEqual(str, 'foo\ufffd'); }