| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b0b16ee commit 889add6
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,6 +35,7 @@ const { | |||
| 35 | 35 | } = require('internal/errors').codes; | |
| 36 | 36 | const { exitCodes: { kUnfinishedTopLevelAwait } } = internalBinding('errors'); | |
| 37 | 37 | const { URL } = require('internal/url'); | |
| 38 | + const { canParse: urlCanParse } = internalBinding('url'); | ||
| 38 | 39 | const { receiveMessageOnPort } = require('worker_threads'); | |
| 39 | 40 | const { | |
| 40 | 41 | isAnyArrayBuffer, | |
@@ -272,17 +273,17 @@ class Hooks { | |||
| 272 | 273 | ||
| 273 | 274 | // Avoid expensive URL instantiation for known-good URLs | |
| 274 | 275 | if (!this.#validatedUrls.has(url)) { | |
| 275 | - try { | ||
| 276 | - new URL(url); | ||
| 277 | - this.#validatedUrls.add(url); | ||
| 278 | - } catch { | ||
| 276 | + // No need to convert to string, since the type is already validated | ||
| 277 | + if (!urlCanParse(url)) { | ||
| 279 | 278 | throw new ERR_INVALID_RETURN_PROPERTY_VALUE( | |
| 280 | 279 | 'a URL string', | |
| 281 | 280 | hookErrIdentifier, | |
| 282 | 281 | 'url', | |
| 283 | 282 | url, | |
| 284 | 283 | ); | |
| 285 | 284 | } | |
| 285 | + | ||
| 286 | + this.#validatedUrls.add(url); | ||
| 286 | 287 | } | |
| 287 | 288 | ||
| 288 | 289 | if ( | |
@@ -352,16 +353,16 @@ class Hooks { | |||
| 352 | 353 | ||
| 353 | 354 | // Avoid expensive URL instantiation for known-good URLs | |
| 354 | 355 | if (!this.#validatedUrls.has(nextUrl)) { | |
| 355 | - try { | ||
| 356 | - new URL(nextUrl); | ||
| 357 | - this.#validatedUrls.add(nextUrl); | ||
| 358 | - } catch { | ||
| 356 | + // No need to convert to string, since the type is already validated | ||
| 357 | + if (!urlCanParse(nextUrl)) { | ||
| 359 | 358 | throw new ERR_INVALID_ARG_VALUE( | |
| 360 | 359 | `${hookErrIdentifier} url`, | |
| 361 | 360 | nextUrl, | |
| 362 | 361 | 'should be a URL string', | |
| 363 | 362 | ); | |
| 364 | 363 | } | |
| 364 | + | ||
| 365 | + this.#validatedUrls.add(nextUrl); | ||
| 365 | 366 | } | |
| 366 | 367 | ||
| 367 | 368 | if (ctx) { validateObject(ctx, `${hookErrIdentifier} context`); } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -42,6 +42,7 @@ const experimentalNetworkImports = | |||
| 42 | 42 | getOptionValue('--experimental-network-imports'); | |
| 43 | 43 | const typeFlag = getOptionValue('--input-type'); | |
| 44 | 44 | const { URL, pathToFileURL, fileURLToPath, isURL } = require('internal/url'); | |
| 45 | + const { canParse: canParseURL } = internalBinding('url'); | ||
| 45 | 46 | const { | |
| 46 | 47 | ERR_INPUT_TYPE_NOT_ALLOWED, | |
| 47 | 48 | ERR_INVALID_ARG_TYPE, | |
@@ -333,14 +334,8 @@ function resolvePackageTargetString( | |||
| 333 | 334 | if (!StringPrototypeStartsWith(target, './')) { | |
| 334 | 335 | if (internal && !StringPrototypeStartsWith(target, '../') && | |
| 335 | 336 | !StringPrototypeStartsWith(target, '/')) { | |
| 336 | - let isURL = false; | ||
| 337 | - try { | ||
| 338 | - new URL(target); | ||
| 339 | - isURL = true; | ||
| 340 | - } catch { | ||
| 341 | - // Continue regardless of error. | ||
| 342 | - } | ||
| 343 | - if (!isURL) { | ||
| 337 | + // No need to convert target to string, since it's already presumed to be | ||
| 338 | + if (!canParseURL(target)) { | ||
| 344 | 339 | const exportTarget = pattern ? | |
| 345 | 340 | RegExpPrototypeSymbolReplace(patternRegEx, target, () => subpath) : | |
| 346 | 341 | target + subpath; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments