@@ -15,7 +15,7 @@ const [nodeMajor, nodeMinor] = process.versions.node.split('.').map(v => Number(
15
15
function nop ( ) { }
16
16
17
17
function isStream ( obj ) {
18
- return obj && typeof obj . pipe === 'function'
18
+ return obj && typeof obj === 'object' && typeof obj . pipe === 'function' && typeof obj . on === 'function'
19
19
}
20
20
21
21
// based on https://github.com/node-fetch/fetch-blob/blob/8ab587d34080de94140b54f07168451e7d0b655e/index.js#L229-L241 (MIT License)
@@ -46,6 +46,12 @@ function buildURL (url, queryParams) {
46
46
function parseURL ( url ) {
47
47
if ( typeof url === 'string' ) {
48
48
url = new URL ( url )
49
+
50
+ if ( ! / ^ h t t p s ? : / . test ( url . origin || url . protocol ) ) {
51
+ throw new InvalidArgumentError ( 'invalid protocol' )
52
+ }
53
+
54
+ return url
49
55
}
50
56
51
57
if ( ! url || typeof url !== 'object' ) {
@@ -375,23 +381,34 @@ function ReadableStreamFrom (iterable) {
375
381
376
382
// The chunk should be a FormData instance and contains
377
383
// all the required methods.
378
- function isFormDataLike ( chunk ) {
379
- return ( chunk &&
380
- chunk . constructor && chunk . constructor . name === 'FormData' &&
381
- typeof chunk === 'object' &&
382
- ( typeof chunk . append === 'function' &&
383
- typeof chunk . delete === 'function' &&
384
- typeof chunk . get === 'function' &&
385
- typeof chunk . getAll === 'function' &&
386
- typeof chunk . has === 'function' &&
387
- typeof chunk . set === 'function' &&
388
- typeof chunk . entries === 'function' &&
389
- typeof chunk . keys === 'function' &&
390
- typeof chunk . values === 'function' &&
391
- typeof chunk . forEach === 'function' )
384
+ function isFormDataLike ( object ) {
385
+ return (
386
+ object &&
387
+ typeof object === 'object' &&
388
+ typeof object . append === 'function' &&
389
+ typeof object . delete === 'function' &&
390
+ typeof object . get === 'function' &&
391
+ typeof object . getAll === 'function' &&
392
+ typeof object . has === 'function' &&
393
+ typeof object . set === 'function' &&
394
+ object [ Symbol . toStringTag ] === 'FormData'
392
395
)
393
396
}
394
397
398
+ function throwIfAborted ( signal ) {
399
+ if ( ! signal ) { return }
400
+ if ( typeof signal . throwIfAborted === 'function' ) {
401
+ signal . throwIfAborted ( )
402
+ } else {
403
+ if ( signal . aborted ) {
404
+ // DOMException not available < v17.0.0
405
+ const err = new Error ( 'The operation was aborted' )
406
+ err . name = 'AbortError'
407
+ throw err
408
+ }
409
+ }
410
+ }
411
+
395
412
const kEnumerableProperty = Object . create ( null )
396
413
kEnumerableProperty . enumerable = true
397
414
@@ -423,6 +440,7 @@ module.exports = {
423
440
getSocketInfo,
424
441
isFormDataLike,
425
442
buildURL,
443
+ throwIfAborted,
426
444
nodeMajor,
427
445
nodeMinor,
428
446
nodeHasAutoSelectFamily : nodeMajor > 18 || ( nodeMajor === 18 && nodeMinor >= 13 )
0 commit comments