Skip to content

Commit 5fa492a

Browse files
committed
test: refactor testcases for surrogate codes
Since the readable web streams already returns USVString The changes made to blob.js and consumers.js are reverted Test cases are added to check surrogate to USVString conversion for ReadablewebStreams Textdecoder and Blob PR-URL: nodejs#40351 Fixes: nodejs#39804
1 parent 442f969 commit 5fa492a

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

lib/internal/blob.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ const {
4242
} = require('internal/util/types');
4343

4444
const {
45-
toUSVString,
4645
createDeferredPromise,
4746
customInspectSymbol: kInspect,
4847
emitExperimentalWarning,
@@ -317,8 +316,7 @@ class Blob {
317316
throw new ERR_INVALID_THIS('Blob');
318317

319318
const dec = new TextDecoder();
320-
const str = dec.decode(await this.arrayBuffer());
321-
return toUSVString(str);
319+
return dec.decode(await this.arrayBuffer());
322320
}
323321

324322
/**

lib/stream/consumers.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ const {
1616
Buffer,
1717
} = require('buffer');
1818

19-
const {
20-
toUSVString
21-
} = require('internal/util');
22-
2319
/**
2420
* @typedef {import('../internal/webstreams/readablestream').ReadableStream
2521
* } ReadableStream
@@ -70,7 +66,7 @@ async function text(stream) {
7066
// Flush the streaming TextDecoder so that any pending
7167
// incomplete multibyte characters are handled.
7268
str += dec.decode(undefined, { stream: false });
73-
return toUSVString(str);
69+
return str;
7470
}
7571

7672
/**

test/parallel/test-blob.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ assert.throws(() => new Blob({}), {
8888
}
8989

9090
{
91-
const b = new Blob(['hello', Buffer.from('world\ud801')]);
92-
assert.strictEqual(b.size, 13);
91+
const b = new Blob(['hello', new Uint8Array([0xed,0xa0,0x88])]);
92+
assert.strictEqual(b.size, 8);
9393
b.text().then(common.mustCall((text) => {
94-
assert.strictEqual(text, 'helloworld\ufffd');
95-
assert.strictEqual(text.length, 11);
94+
assert.strictEqual(text, 'hello\ufffd\ufffd\ufffd');
95+
assert.strictEqual(text.length, 8);
9696
}));
9797
}
9898

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

+15
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,18 @@ if (common.hasIntl) {
191191
}
192192
);
193193
}
194+
195+
// Test TextDecoder for surrogate code points
196+
{
197+
const decoder = new TextDecoder();
198+
const chunk = Buffer.from([0x66, 0x6f, 0x6f, 0xed, 0xa0, 0x80]); // foo + U+D800
199+
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');
208+
}

0 commit comments

Comments
 (0)