From 6b54056e8b0c868686488f77200d7c5a4b3eaf81 Mon Sep 17 00:00:00 2001 From: d068544 Date: Mon, 17 Oct 2022 19:24:52 +0200 Subject: [PATCH] add protocol 2 --- src/common/urlUtils.ts | 9 +++++++++ src/targets/browser/browserPathResolver.ts | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) 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);