Skip to content

Commit

Permalink
add protocol 2
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankEssenberger committed Oct 17, 2022
1 parent 9b009e4 commit 6b54056
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/common/urlUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions src/targets/browser/browserPathResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -205,7 +205,7 @@ export class BrowserSourcePathResolver extends SourcePathResolverBase<IOptions>
defaultPathMappingResolver,
this.logger,
);
if (isValidUrl(computedSourceRoot)) {
if (isValidUrlWithProtocol(computedSourceRoot)) {
return new URL(url, computedSourceRoot).href;
}
return properResolve(computedSourceRoot, url);
Expand Down

0 comments on commit 6b54056

Please sign in to comment.