@@ -58,31 +58,31 @@ function parseURL (url) {
5858 throw new InvalidArgumentError ( 'Invalid URL: The URL argument must be a non-null object.' )
5959 }
6060
61- if ( url . port != null && url . port !== '' && ! Number . isFinite ( parseInt ( url . port ) ) ) {
62- throw new InvalidArgumentError ( 'Invalid URL: port must be a valid integer or a string representation of an integer .' )
61+ if ( ! / ^ h t t p s ? : / . test ( url . origin || url . protocol ) ) {
62+ throw new InvalidArgumentError ( 'Invalid URL protocol: the URL must start with `http:` or `https:` .' )
6363 }
6464
65- if ( url . path != null && typeof url . path !== 'string' ) {
66- throw new InvalidArgumentError ( 'Invalid URL path: the path must be a string or null/undefined.' )
67- }
65+ if ( ! ( url instanceof URL ) ) {
66+ if ( url . port != null && url . port !== '' && ! Number . isFinite ( parseInt ( url . port ) ) ) {
67+ throw new InvalidArgumentError ( 'Invalid URL: port must be a valid integer or a string representation of an integer.' )
68+ }
6869
69- if ( url . pathname != null && typeof url . pathname !== 'string' ) {
70- throw new InvalidArgumentError ( 'Invalid URL pathname : the pathname must be a string or null/undefined.' )
71- }
70+ if ( url . path != null && typeof url . path !== 'string' ) {
71+ throw new InvalidArgumentError ( 'Invalid URL path : the path must be a string or null/undefined.' )
72+ }
7273
73- if ( url . hostname != null && typeof url . hostname !== 'string' ) {
74- throw new InvalidArgumentError ( 'Invalid URL hostname : the hostname must be a string or null/undefined.' )
75- }
74+ if ( url . pathname != null && typeof url . pathname !== 'string' ) {
75+ throw new InvalidArgumentError ( 'Invalid URL pathname : the pathname must be a string or null/undefined.' )
76+ }
7677
77- if ( url . origin != null && typeof url . origin !== 'string' ) {
78- throw new InvalidArgumentError ( 'Invalid URL origin : the origin must be a string or null/undefined.' )
79- }
78+ if ( url . hostname != null && typeof url . hostname !== 'string' ) {
79+ throw new InvalidArgumentError ( 'Invalid URL hostname : the hostname must be a string or null/undefined.' )
80+ }
8081
81- if ( ! / ^ h t t p s ? : / . test ( url . origin || url . protocol ) ) {
82- throw new InvalidArgumentError ( 'Invalid URL protocol : the URL must start with `http:` or `https:` .' )
83- }
82+ if ( url . origin != null && typeof url . origin !== 'string' ) {
83+ throw new InvalidArgumentError ( 'Invalid URL origin : the origin must be a string or null/undefined .' )
84+ }
8485
85- if ( ! ( url instanceof URL ) ) {
8686 const port = url . port != null
8787 ? url . port
8888 : ( url . protocol === 'https:' ? 443 : 80 )
0 commit comments