test: add tests for invalid UTF-8 · nodejs/node@c002930 · GitHub
Skip to content

Commit c002930

Browse files
git-srinivasdanielleadams
authored andcommitted
test: add tests for invalid UTF-8
Verify that `Blob.prototype.text()`, `streamConsumers.text()` and `TextDecoder.prototype.decode()` work as expected with invalid UTF-8. PR-URL: #40351 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com>
1 parent e60841b commit c002930

3 files changed

Lines changed: 31 additions & 0 deletions

File tree

test/parallel/test-blob.js

Lines changed: 9 additions & 0 deletions

test/parallel/test-stream-consumers.js

Lines changed: 14 additions & 0 deletions
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

@@ -73,6 +74,19 @@ const kArrayBuffer =
7374
setTimeout(() => passthrough.end('there'), 10);
7475
}
7576

77+
{
78+
const readable = new Readable({
79+
read() {}
80+
});
81+
82+
text(readable).then((data) => {
83+
assert.strictEqual(data, 'foo\ufffd\ufffd\ufffd');
84+
});
85+
86+
readable.push(new Uint8Array([0x66, 0x6f, 0x6f, 0xed, 0xa0, 0x80]));
87+
readable.push(null);
88+
}
89+
7690
{
7791
const passthrough = new PassThrough();
7892

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

Lines changed: 8 additions & 0 deletions

0 commit comments

Comments
 (0)