diff --git a/src/common/urlUtils.ts b/src/common/urlUtils.ts index 8ee9f7d4e..a33677f6c 100644 --- a/src/common/urlUtils.ts +++ b/src/common/urlUtils.ts @@ -199,6 +199,15 @@ export function completeUrlEscapingRoot(base: string | undefined, relative: stri } export function isValidUrl(url: string): boolean { + try { + new URL(url); + return true; + } catch (e) { + return false; + } +} + +export function isValidUrlWithProtocol(url: string): boolean { try { const parsed = new URL(url); diff --git a/src/targets/browser/browserPathResolver.ts b/src/targets/browser/browserPathResolver.ts index bdf5347a1..ab925d3ef 100644 --- a/src/targets/browser/browserPathResolver.ts +++ b/src/targets/browser/browserPathResolver.ts @@ -22,7 +22,7 @@ import { } from '../../common/sourceMaps/sourceMapResolutionUtils'; import { IUrlResolution } from '../../common/sourcePathResolver'; import * as utils from '../../common/urlUtils'; -import { isValidUrl, urlToRegex } from '../../common/urlUtils'; +import { isValidUrlWithProtocol, urlToRegex } from '../../common/urlUtils'; import { PathMapping } from '../../configuration'; import { ISourcePathResolverOptions, SourcePathResolverBase } from '../sourcePathResolver'; @@ -205,7 +205,7 @@ export class BrowserSourcePathResolver extends SourcePathResolverBase defaultPathMappingResolver, this.logger, ); - if (isValidUrl(computedSourceRoot)) { + if (isValidUrlWithProtocol(computedSourceRoot)) { return new URL(url, computedSourceRoot).href; } return properResolve(computedSourceRoot, url);