File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -388,10 +388,6 @@ webidl.converters.DOMString = function (V, opts = {}) {
388388 return String ( V )
389389}
390390
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-
395391// https://webidl.spec.whatwg.org/#es-ByteString
396392webidl . converters . ByteString = function ( V ) {
397393 // 1. Let x be ? ToString(V).
@@ -400,8 +396,15 @@ webidl.converters.ByteString = function (V) {
400396
401397 // 2. If the value of any element of x is greater than
402398 // 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+ }
405408 }
406409
407410 // 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) => {
189189 webidl . converters . ByteString ( '' )
190190 } )
191191
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+
192201 t . end ( )
193202} )
You can’t perform that action at this time.
0 commit comments