| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7c534bf commit 59ef178
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,7 +28,6 @@ const { | |||
| 28 | 28 | ||
| 29 | 29 | const { | |
| 30 | 30 | codes: { | |
| 31 | - ERR_INVALID_ARG_TYPE, | ||
| 32 | 31 | ERR_INVALID_ARG_VALUE, | |
| 33 | 32 | ERR_OUT_OF_RANGE, | |
| 34 | 33 | }, | |
@@ -39,6 +38,7 @@ const { | |||
| 39 | 38 | validateFunction, | |
| 40 | 39 | validateInteger, | |
| 41 | 40 | validateObject, | |
| 41 | + validateString, | ||
| 42 | 42 | } = require('internal/validators'); | |
| 43 | 43 | ||
| 44 | 44 | const { | |
@@ -196,10 +196,7 @@ function validateBaseConsumerOptions(options) { | |||
| 196 | 196 | validateInteger(options.limit, 'options.limit', 0); | |
| 197 | 197 | } | |
| 198 | 198 | if (options.encoding !== undefined) { | |
| 199 | - if (typeof options.encoding !== 'string') { | ||
| 200 | - throw new ERR_INVALID_ARG_TYPE('options.encoding', 'string', | ||
| 201 | - options.encoding); | ||
| 202 | - } | ||
| 199 | + validateString(options.encoding, 'options.encoding'); | ||
| 203 | 200 | try { | |
| 204 | 201 | new TextDecoder(options.encoding); | |
| 205 | 202 | } catch { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -143,6 +143,20 @@ function testTextSyncUnsupportedEncodingThrowsRangeError() { | |||
| 143 | 143 | ); | |
| 144 | 144 | } | |
| 145 | 145 | ||
| 146 | + async function testTextNonStringEncodingThrowsTypeError() { | ||
| 147 | + await assert.rejects( | ||
| 148 | + () => text(from('hello'), { encoding: 1 }), | ||
| 149 | + { code: 'ERR_INVALID_ARG_TYPE' }, | ||
| 150 | + ); | ||
| 151 | + } | ||
| 152 | + | ||
| 153 | + function testTextSyncNonStringEncodingThrowsTypeError() { | ||
| 154 | + assert.throws( | ||
| 155 | + () => textSync(fromSync('hello'), { encoding: 1 }), | ||
| 156 | + { code: 'ERR_INVALID_ARG_TYPE' }, | ||
| 157 | + ); | ||
| 158 | + } | ||
| 159 | + | ||
| 146 | 160 | Promise.all([ | |
| 147 | 161 | testTextSyncBasic(), | |
| 148 | 162 | testTextAsync(), | |
@@ -159,4 +173,6 @@ Promise.all([ | |||
| 159 | 173 | testTextSyncBOMStripped(), | |
| 160 | 174 | testTextUnsupportedEncodingThrowsRangeError(), | |
| 161 | 175 | testTextSyncUnsupportedEncodingThrowsRangeError(), | |
| 176 | + testTextNonStringEncodingThrowsTypeError(), | ||
| 177 | + testTextSyncNonStringEncodingThrowsTypeError(), | ||
| 162 | 178 | ]).then(common.mustCall()); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments