Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions lib/internal/streams/iter/consumers.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,7 +28,6 @@ const {

const {
codes: {
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ARG_VALUE,
ERR_OUT_OF_RANGE,
},
Expand All@@ -39,6 +38,7 @@ const {
validateFunction,
validateInteger,
validateObject,
validateString,
} = require('internal/validators');

const {
Expand DownExpand Up@@ -196,10 +196,7 @@ function validateBaseConsumerOptions(options) {
validateInteger(options.limit, 'options.limit', 0);
}
if (options.encoding !== undefined) {
if (typeof options.encoding !== 'string') {
throw new ERR_INVALID_ARG_TYPE('options.encoding', 'string',
options.encoding);
}
validateString(options.encoding, 'options.encoding');
try {
new TextDecoder(options.encoding);
} catch {
Expand Down
16 changes: 16 additions & 0 deletions test/parallel/test-stream-iter-consumers-text.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -143,6 +143,20 @@ function testTextSyncUnsupportedEncodingThrowsRangeError() {
);
}

async function testTextNonStringEncodingThrowsTypeError() {
await assert.rejects(
() => text(from('hello'), { encoding: 1 }),
{ code: 'ERR_INVALID_ARG_TYPE' },
);
}

function testTextSyncNonStringEncodingThrowsTypeError() {
assert.throws(
() => textSync(fromSync('hello'), { encoding: 1 }),
{ code: 'ERR_INVALID_ARG_TYPE' },
);
}

Promise.all([
testTextSyncBasic(),
testTextAsync(),
Expand All@@ -159,4 +173,6 @@ Promise.all([
testTextSyncBOMStripped(),
testTextUnsupportedEncodingThrowsRangeError(),
testTextSyncUnsupportedEncodingThrowsRangeError(),
testTextNonStringEncodingThrowsTypeError(),
testTextSyncNonStringEncodingThrowsTypeError(),
]).then(common.mustCall());
Loading