Comparing version 13.2.9 to 13.3.0
@@ -14,2 +14,3 @@ 'use strict' | ||
const { URL, Url: LegacyUrl } = url | ||
let fs | ||
@@ -24,3 +25,42 @@ | ||
/** | ||
* @param {string|RegExp|url.url} basePath | ||
* Normalizes the passed url for consistent internal processing | ||
* @param {string|LegacyUrl|URL} u | ||
*/ | ||
function normalizeUrl(u) { | ||
if (!(u instanceof URL)) { | ||
if (u instanceof LegacyUrl) { | ||
return normalizeUrl(new URL(url.format(u))) | ||
} | ||
// If the url is invalid, let the URL library report it | ||
return normalizeUrl(new URL(u)) | ||
} | ||
if (!/https?:/.test(u.protocol)) { | ||
throw new TypeError( | ||
`Protocol '${u.protocol}' not recognized. This commonly occurs when a hostname and port are included without a protocol, producing a URL that is valid but confusing, and probably not what you want.` | ||
) | ||
} | ||
return { | ||
href: u.href, | ||
origin: u.origin, | ||
protocol: u.protocol, | ||
username: u.username, | ||
password: u.password, | ||
host: u.host, | ||
hostname: | ||
// strip brackets from IPv6 | ||
typeof u.hostname === 'string' && u.hostname.startsWith('[') | ||
? u.hostname.slice(1, -1) | ||
: u.hostname, | ||
port: u.port || (u.protocol === 'http:' ? 80 : 443), | ||
pathname: u.pathname, | ||
search: u.search, | ||
searchParams: u.searchParams, | ||
hash: u.hash, | ||
} | ||
} | ||
/** | ||
* @param {string|RegExp|LegacyUrl|URL} basePath | ||
* @param {Object} options | ||
@@ -57,5 +97,4 @@ * @param {boolean} options.allowUnmocked | ||
if (!(basePath instanceof RegExp)) { | ||
this.urlParts = url.parse(basePath) | ||
this.port = | ||
this.urlParts.port || (this.urlParts.protocol === 'http:' ? 80 : 443) | ||
this.urlParts = normalizeUrl(basePath) | ||
this.port = this.urlParts.port | ||
this.basePathname = this.urlParts.pathname.replace(/\/$/, '') | ||
@@ -62,0 +101,0 @@ this.basePath = `${this.urlParts.protocol}//${this.urlParts.hostname}:${this.port}` |
@@ -10,3 +10,3 @@ { | ||
], | ||
"version": "13.2.9", | ||
"version": "13.3.0", | ||
"author": "Pedro Teixeira <pedro.teixeira@gmail.com>", | ||
@@ -33,3 +33,3 @@ "repository": { | ||
"@definitelytyped/dtslint": "^0.0.112", | ||
"@sinonjs/fake-timers": "^9.0.0", | ||
"@sinonjs/fake-timers": "^10.0.0", | ||
"assert-rejects": "^1.0.0", | ||
@@ -54,3 +54,3 @@ "chai": "^4.1.2", | ||
"semantic-release": "^19.0.2", | ||
"sinon": "^14.0.0", | ||
"sinon": "^15.0.1", | ||
"sinon-chai": "^3.7.0", | ||
@@ -57,0 +57,0 @@ "typescript": "^4.2.2" |
@@ -162,3 +162,3 @@ # Nock | ||
The request hostname can be a string or a RegExp. | ||
The request hostname can be a string, URL, or a RegExp. | ||
@@ -172,2 +172,8 @@ ```js | ||
```js | ||
const scope = nock(new URL('http://www.example.com')) | ||
.get('/resource') | ||
.reply(200, 'domain matched') | ||
``` | ||
```js | ||
const scope = nock(/example\.com/) | ||
@@ -174,0 +180,0 @@ .get('/resource') |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
179426
3504
1658