@@ -15,7 +15,7 @@ const [nodeMajor, nodeMinor] = process.versions.node.split('.').map(v => Number(
1515function nop ( ) { }
1616
1717function isStream ( obj ) {
18- return obj && typeof obj . pipe === 'function'
18+ return obj && typeof obj === 'object' && typeof obj . pipe === 'function' && typeof obj . on === 'function'
1919}
2020
2121// 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) {
4646function parseURL ( url ) {
4747 if ( typeof url === 'string' ) {
4848 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
4955 }
5056
5157 if ( ! url || typeof url !== 'object' ) {
@@ -375,23 +381,34 @@ function ReadableStreamFrom (iterable) {
375381
376382// The chunk should be a FormData instance and contains
377383// 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'
392395 )
393396}
394397
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+
395412const kEnumerableProperty = Object . create ( null )
396413kEnumerableProperty . enumerable = true
397414
@@ -423,6 +440,7 @@ module.exports = {
423440 getSocketInfo,
424441 isFormDataLike,
425442 buildURL,
443+ throwIfAborted,
426444 nodeMajor,
427445 nodeMinor,
428446 nodeHasAutoSelectFamily : nodeMajor > 18 || ( nodeMajor === 18 && nodeMinor >= 13 )
0 commit comments