File tree Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -388,10 +388,6 @@ webidl.converters.DOMString = function (V, opts = {}) {
388
388
return String ( V )
389
389
}
390
390
391
- // Check for 0 or more characters outside of the latin1 range.
392
- // eslint-disable-next-line no-control-regex
393
- const isLatin1 = / ^ [ \u0000 - \u00ff ] { 0 , } $ /
394
-
395
391
// https://webidl.spec.whatwg.org/#es-ByteString
396
392
webidl . converters . ByteString = function ( V ) {
397
393
// 1. Let x be ? ToString(V).
@@ -400,8 +396,15 @@ webidl.converters.ByteString = function (V) {
400
396
401
397
// 2. If the value of any element of x is greater than
402
398
// 255, then throw a TypeError.
403
- if ( ! isLatin1 . test ( x ) ) {
404
- throw new TypeError ( 'Argument is not a ByteString' )
399
+ for ( let index = 0 ; index < x . length ; index ++ ) {
400
+ const charCode = x . charCodeAt ( index )
401
+
402
+ if ( charCode > 255 ) {
403
+ throw new TypeError (
404
+ 'Cannot convert argument to a ByteString because the character at' +
405
+ `index ${ index } has a value of ${ charCode } which is greater than 255.`
406
+ )
407
+ }
405
408
}
406
409
407
410
// 3. Return an IDL ByteString value whose length is the
Original file line number Diff line number Diff line change @@ -189,5 +189,14 @@ test('ByteString', (t) => {
189
189
webidl . converters . ByteString ( '' )
190
190
} )
191
191
192
+ // https://github.com/nodejs/undici/issues/1590
193
+ t . throws ( ( ) => {
194
+ const char = String . fromCharCode ( 256 )
195
+ webidl . converters . ByteString ( `invalid${ char } char` )
196
+ } , {
197
+ message : 'Cannot convert argument to a ByteString because the character at' +
198
+ 'index 7 has a value of 256 which is greater than 255.'
199
+ } )
200
+
192
201
t . end ( )
193
202
} )
You can’t perform that action at this time.
0 commit comments