From 538aed78cafa7f8945d21c2c32fe8bf60f8e5444 Mon Sep 17 00:00:00 2001 From: d068544 Date: Fri, 14 Oct 2022 17:59:21 +0200 Subject: [PATCH 01/13] linter put other tests back in --- src/adapter/scriptSkipper/implementation.ts | 1 + src/adapter/sources.ts | 13 ++++++---- .../sourceMaps/sourceMapResolutionUtils.ts | 14 +++++++---- src/common/urlUtils.ts | 17 +++++++++++++ src/targets/browser/browserPathResolver.ts | 24 +++++++++---------- .../sources-supports-remote-sources-1424.txt | 23 ++++++++++++++++++ src/test/sources/sourcesTest.ts | 10 ++++++++ testWorkspace/web/remote-test/string.js | 10 ++++++++ testWorkspace/web/remote-test/string.js.map | 3 +++ testWorkspace/web/remote-test/string.ts | 9 +++++++ 10 files changed, 102 insertions(+), 22 deletions(-) create mode 100644 src/test/sources/sources-supports-remote-sources-1424.txt create mode 100644 testWorkspace/web/remote-test/string.js create mode 100644 testWorkspace/web/remote-test/string.js.map create mode 100644 testWorkspace/web/remote-test/string.ts diff --git a/src/adapter/scriptSkipper/implementation.ts b/src/adapter/scriptSkipper/implementation.ts index 5efb2ab72..86fefb6f6 100644 --- a/src/adapter/scriptSkipper/implementation.ts +++ b/src/adapter/scriptSkipper/implementation.ts @@ -260,6 +260,7 @@ export class ScriptSkipper { if ( !skipped && source.absolutePath && + urlUtils.isAbsolute(source.absolutePath) && this._testSkipAuthored(urlUtils.absolutePathToFileUrl(source.absolutePath)) ) { this.setIsUrlBlackboxSkipped(url, true); diff --git a/src/adapter/sources.ts b/src/adapter/sources.ts index a833f04bb..6b30523da 100644 --- a/src/adapter/sources.ts +++ b/src/adapter/sources.ts @@ -1082,9 +1082,10 @@ export class SourceContainer { const todo: Promise[] = []; for (const url of map.sources) { const absolutePath = await this.sourcePathResolver.urlToAbsolutePath({ url, map }); - const resolvedUrl = absolutePath - ? utils.absolutePathToFileUrl(absolutePath) - : map.computedSourceUrl(url); + const resolvedUrl = + absolutePath && utils.isAbsolute(absolutePath) + ? utils.absolutePathToFileUrl(absolutePath) + : map.computedSourceUrl(url); const existing = this._sourceMapSourcesByUrl.get(resolvedUrl); if (existing) { @@ -1106,7 +1107,6 @@ export class SourceContainer { resolvedUrl, }); - const fileUrl = absolutePath && utils.absolutePathToFileUrl(absolutePath); const smContent = this.sourceMapFactory.guardSourceMapFn( map, () => map.sourceContentFor(url, true), @@ -1129,6 +1129,10 @@ export class SourceContainer { } } + const fileUrl = + absolutePath && utils.isAbsolute(absolutePath) + ? utils.absolutePathToFileUrl(absolutePath) + : absolutePath; const source = new SourceFromMap( this, resolvedUrl, @@ -1146,6 +1150,7 @@ export class SourceContainer { ); source.compiledToSourceUrl.set(compiled, url); compiled.sourceMap.sourceByUrl.set(url, source); + todo.push(this._addSource(source)); } diff --git a/src/common/sourceMaps/sourceMapResolutionUtils.ts b/src/common/sourceMaps/sourceMapResolutionUtils.ts index 3d3023033..d725645e6 100644 --- a/src/common/sourceMaps/sourceMapResolutionUtils.ts +++ b/src/common/sourceMaps/sourceMapResolutionUtils.ts @@ -20,7 +20,6 @@ export function getFullSourceEntry(sourceRoot: string | undefined, sourcePath: s if (!sourceRoot.endsWith('/')) { sourceRoot += '/'; } - return sourceRoot + sourcePath; } @@ -35,12 +34,13 @@ export async function getComputedSourceRoot( logger: ILogger, ): Promise { generatedPath = utils.fileUrlToAbsolutePath(generatedPath) || generatedPath; - let absSourceRoot: string; if (sourceRoot) { if (utils.isFileUrl(sourceRoot)) { // sourceRoot points to a local path like "file:///c:/project/src", make it an absolute path absSourceRoot = utils.fileUrlToAbsolutePath(sourceRoot); + } else if (utils.isURL(sourceRoot)) { + absSourceRoot = sourceRoot; } else if (utils.isAbsolute(sourceRoot)) { // sourceRoot is like "/src", should be like http://localhost/src, resolve to a local path using pathMaping. // If path mappings do not apply (e.g. node), assume that sourceRoot is actually a local absolute path. @@ -79,9 +79,13 @@ export async function getComputedSourceRoot( ); } - absSourceRoot = utils.stripTrailingSlash(absSourceRoot); - absSourceRoot = fixDriveLetterAndSlashes(absSourceRoot); - + if (!utils.isURL(absSourceRoot)) { + absSourceRoot = utils.stripTrailingSlash(absSourceRoot); + absSourceRoot = fixDriveLetterAndSlashes(absSourceRoot); + } else { + //guarantees one slash in the end for later join with sources files + absSourceRoot = new URL(absSourceRoot).href; + } return absSourceRoot; } diff --git a/src/common/urlUtils.ts b/src/common/urlUtils.ts index 973009292..1a8d5e7f0 100644 --- a/src/common/urlUtils.ts +++ b/src/common/urlUtils.ts @@ -301,6 +301,11 @@ export function fileUrlToNetworkPath(urlOrPath: string): string { // TODO: this does not escape/unescape special characters, but it should. export function absolutePathToFileUrl(absolutePath: string): string { + if (absolutePath.includes('://')) { + throw new Error( + `You call the absolutePathToFileUrl on a path starting containg a different protocol: ${absolutePath}`, + ); + } if (platform === 'win32') { return 'file:///' + platformPathToUrlPath(absolutePath); } @@ -314,6 +319,18 @@ export function isAbsolute(_path: string): boolean { return path.posix.isAbsolute(_path) || path.win32.isAbsolute(_path); } +/** + * Returns whether the path is a Windows or posix path. + */ +export function isURL(input: string): boolean { + try { + const url = new URL(input); + return url.protocol === 'http:' || url.protocol === 'https:'; + } catch (_) { + return false; + } +} + /** * Returns whether the uri looks like a data URI. */ diff --git a/src/targets/browser/browserPathResolver.ts b/src/targets/browser/browserPathResolver.ts index d429551b5..0c39ed91e 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 { urlToRegex } from '../../common/urlUtils'; +import { isURL, urlToRegex } from '../../common/urlUtils'; import { PathMapping } from '../../configuration'; import { ISourcePathResolverOptions, SourcePathResolverBase } from '../sourcePathResolver'; @@ -87,7 +87,6 @@ export class BrowserSourcePathResolver extends SourcePathResolverBase if (queryCharacter !== -1 && url.slice(queryCharacter - 4, queryCharacter) !== '.vue') { url = url.slice(0, queryCharacter); } - return map ? this.sourceMapSourceToAbsolute(url, map) : this.simpleUrlToAbsolute(url); } @@ -170,7 +169,6 @@ export class BrowserSourcePathResolver extends SourcePathResolverBase } url = this.normalizeSourceMapUrl(url); - const { pathMapping } = this.options; const fullSourceEntry = getFullSourceEntry(map.sourceRoot, url); let mappedFullSourceEntry = this.sourceMapOverrides.apply(fullSourceEntry); @@ -200,18 +198,18 @@ export class BrowserSourcePathResolver extends SourcePathResolverBase } if (!path.isAbsolute(url)) { - return properResolve( - await getComputedSourceRoot( - map.sourceRoot, - map.metadata.compiledPath, - pathMapping, - defaultPathMappingResolver, - this.logger, - ), - url, + const computedSourceRoot = await getComputedSourceRoot( + map.sourceRoot, + map.metadata.compiledPath, + pathMapping, + defaultPathMappingResolver, + this.logger, ); + if (isURL(computedSourceRoot)) { + return new URL(url, computedSourceRoot).href; + } + return properResolve(computedSourceRoot, url); } - return fixDriveLetterAndSlashes(url); } diff --git a/src/test/sources/sources-supports-remote-sources-1424.txt b/src/test/sources/sources-supports-remote-sources-1424.txt new file mode 100644 index 000000000..a11d59182 --- /dev/null +++ b/src/test/sources/sources-supports-remote-sources-1424.txt @@ -0,0 +1,23 @@ + +Source event for +{ + reason : new + source : { + name : localhost꞉8001/remote-test/string.ts + path : localhost꞉8001/remote-test/string.ts + sourceReference : + } +} +text/javascript +--------- +let i = 0; +i++; +debugger; +i++; +i++; +i++; +i++; +i++; +console.log(i);//ts file + +--------- diff --git a/src/test/sources/sourcesTest.ts b/src/test/sources/sourcesTest.ts index 503d1e5f9..e04bed112 100644 --- a/src/test/sources/sourcesTest.ts +++ b/src/test/sources/sourcesTest.ts @@ -102,6 +102,16 @@ describe('sources', () => { handle.assertLog({ substring: true }); }); + itIntegrates('supports remote sources (#1424)', async ({ r }) => { + const p = await r.launchUrlAndLoad('index.html'); + p.addScriptTag('remote-test/string.js'); + + const source = await p.waitForSource('string.ts'); + await dumpSource(p, source, ''); + + p.assertLog(); + }); + itIntegrates('works with relative webpack sourcemaps (#479)', async ({ r }) => { const p = await r.launchUrl('webpack/relative-paths.html'); diff --git a/testWorkspace/web/remote-test/string.js b/testWorkspace/web/remote-test/string.js new file mode 100644 index 000000000..0f418f44a --- /dev/null +++ b/testWorkspace/web/remote-test/string.js @@ -0,0 +1,10 @@ +let i = 0; +i++; +debugger; +i++; +i++; +i++; +i++; +i++; +console.log('123'); +//# sourceMappingURL=string.js.map diff --git a/testWorkspace/web/remote-test/string.js.map b/testWorkspace/web/remote-test/string.js.map new file mode 100644 index 000000000..d030a8466 --- /dev/null +++ b/testWorkspace/web/remote-test/string.js.map @@ -0,0 +1,3 @@ +{"version":3,"file":"string.js","sourceRoot":"http://localhost:8001/remote-test/","sources":["string.ts"],"names":[],"mappings":";AAAA,IAAI,CAAC,GAAG,CAAC,CAAC;AACV,CAAC,EAAE,CAAC;AACJ,QAAQ,CAAC;AACT,CAAC,EAAE,CAAC;AACJ,CAAC,EAAE,CAAC;AACJ,CAAC,EAAE,CAAC;AACJ,CAAC,EAAE,CAAC;AACJ,CAAC,EAAE,CAAC;AACJ,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC"} + + diff --git a/testWorkspace/web/remote-test/string.ts b/testWorkspace/web/remote-test/string.ts new file mode 100644 index 000000000..9326d9659 --- /dev/null +++ b/testWorkspace/web/remote-test/string.ts @@ -0,0 +1,9 @@ +let i = 0; +i++; +debugger; +i++; +i++; +i++; +i++; +i++; +console.log(i);//ts file From e0c297d50d7f123058f91ebe163da6b1ee903b11 Mon Sep 17 00:00:00 2001 From: d068544 Date: Fri, 14 Oct 2022 18:09:48 +0200 Subject: [PATCH 02/13] improve wording --- src/common/urlUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/urlUtils.ts b/src/common/urlUtils.ts index 1a8d5e7f0..2d85b07c9 100644 --- a/src/common/urlUtils.ts +++ b/src/common/urlUtils.ts @@ -303,7 +303,7 @@ export function fileUrlToNetworkPath(urlOrPath: string): string { export function absolutePathToFileUrl(absolutePath: string): string { if (absolutePath.includes('://')) { throw new Error( - `You call the absolutePathToFileUrl on a path starting containg a different protocol: ${absolutePath}`, + `You are using the 'absolutePathToFileUrl()' on a string already containing a protocol: ${absolutePath}`, ); } if (platform === 'win32') { From 5f4195d47757312c25f558239b3d706ae7240cd2 Mon Sep 17 00:00:00 2001 From: d068544 Date: Fri, 14 Oct 2022 19:47:34 +0200 Subject: [PATCH 03/13] try without throwing --- src/common/urlUtils.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/common/urlUtils.ts b/src/common/urlUtils.ts index 2d85b07c9..7afef7928 100644 --- a/src/common/urlUtils.ts +++ b/src/common/urlUtils.ts @@ -302,9 +302,9 @@ export function fileUrlToNetworkPath(urlOrPath: string): string { // TODO: this does not escape/unescape special characters, but it should. export function absolutePathToFileUrl(absolutePath: string): string { if (absolutePath.includes('://')) { - throw new Error( - `You are using the 'absolutePathToFileUrl()' on a string already containing a protocol: ${absolutePath}`, - ); + // throw new Error( + // `You are using the 'absolutePathToFileUrl()' on a string already containing a protocol: ${absolutePath}`, + // ); } if (platform === 'win32') { return 'file:///' + platformPathToUrlPath(absolutePath); From 2ec463028cdff447ba166d49d0b0f35ff328787f Mon Sep 17 00:00:00 2001 From: d068544 Date: Mon, 17 Oct 2022 14:52:57 +0200 Subject: [PATCH 04/13] add one more check and some refactoring --- src/adapter/breakpoints/breakpointBase.ts | 8 ++++++-- .../sourceMaps/sourceMapResolutionUtils.ts | 4 ++-- src/common/urlUtils.ts | 19 ++++--------------- src/targets/browser/browserPathResolver.ts | 4 ++-- src/test/sources/sourcesTest.ts | 2 +- src/test/testRunner.ts | 18 +++++++++--------- .../web/remote-test/{string.js => code.js} | 0 .../{string.js.map => code.js.map} | 0 .../web/remote-test/{string.ts => code.ts} | 0 9 files changed, 24 insertions(+), 31 deletions(-) rename testWorkspace/web/remote-test/{string.js => code.js} (100%) rename testWorkspace/web/remote-test/{string.js.map => code.js.map} (100%) rename testWorkspace/web/remote-test/{string.ts => code.ts} (100%) diff --git a/src/adapter/breakpoints/breakpointBase.ts b/src/adapter/breakpoints/breakpointBase.ts index 8abc51a1b..af881d999 100644 --- a/src/adapter/breakpoints/breakpointBase.ts +++ b/src/adapter/breakpoints/breakpointBase.ts @@ -4,7 +4,7 @@ import Cdp from '../../cdp/api'; import { LogTag } from '../../common/logging'; -import { absolutePathToFileUrl, urlToRegex } from '../../common/urlUtils'; +import { absolutePathToFileUrl, isAbsolute, urlToRegex } from '../../common/urlUtils'; import Dap from '../../dap/api'; import { BreakpointManager } from '../breakpoints'; import { base1To0, IUiLocation, Source, SourceFromMap, uiToRawOffset } from '../sources'; @@ -492,7 +492,11 @@ export abstract class Breakpoint { await this._setByUrl(thread, url, lineColumn); if (this.source.path !== url && this.source.path !== undefined) { - await this._setByUrl(thread, absolutePathToFileUrl(this.source.path), lineColumn); + await this._setByUrl( + thread, + isAbsolute(this.source.path) ? absolutePathToFileUrl(this.source.path) : this.source.path, + lineColumn, + ); } } } diff --git a/src/common/sourceMaps/sourceMapResolutionUtils.ts b/src/common/sourceMaps/sourceMapResolutionUtils.ts index d725645e6..1d3991d72 100644 --- a/src/common/sourceMaps/sourceMapResolutionUtils.ts +++ b/src/common/sourceMaps/sourceMapResolutionUtils.ts @@ -39,7 +39,7 @@ export async function getComputedSourceRoot( if (utils.isFileUrl(sourceRoot)) { // sourceRoot points to a local path like "file:///c:/project/src", make it an absolute path absSourceRoot = utils.fileUrlToAbsolutePath(sourceRoot); - } else if (utils.isURL(sourceRoot)) { + } else if (utils.isValidUrl(sourceRoot)) { absSourceRoot = sourceRoot; } else if (utils.isAbsolute(sourceRoot)) { // sourceRoot is like "/src", should be like http://localhost/src, resolve to a local path using pathMaping. @@ -79,7 +79,7 @@ export async function getComputedSourceRoot( ); } - if (!utils.isURL(absSourceRoot)) { + if (!utils.isValidUrl(absSourceRoot)) { absSourceRoot = utils.stripTrailingSlash(absSourceRoot); absSourceRoot = fixDriveLetterAndSlashes(absSourceRoot); } else { diff --git a/src/common/urlUtils.ts b/src/common/urlUtils.ts index 7afef7928..415b0b94c 100644 --- a/src/common/urlUtils.ts +++ b/src/common/urlUtils.ts @@ -302,9 +302,10 @@ export function fileUrlToNetworkPath(urlOrPath: string): string { // TODO: this does not escape/unescape special characters, but it should. export function absolutePathToFileUrl(absolutePath: string): string { if (absolutePath.includes('://')) { - // throw new Error( - // `You are using the 'absolutePathToFileUrl()' on a string already containing a protocol: ${absolutePath}`, - // ); + throw new Error( + `You are using the 'absolutePathToFileUrl()' on a string already containing a protocol: ${absolutePath}`, + ); + console.error('FE123' + absolutePath); } if (platform === 'win32') { return 'file:///' + platformPathToUrlPath(absolutePath); @@ -319,18 +320,6 @@ export function isAbsolute(_path: string): boolean { return path.posix.isAbsolute(_path) || path.win32.isAbsolute(_path); } -/** - * Returns whether the path is a Windows or posix path. - */ -export function isURL(input: string): boolean { - try { - const url = new URL(input); - return url.protocol === 'http:' || url.protocol === 'https:'; - } catch (_) { - return false; - } -} - /** * Returns whether the uri looks like a data URI. */ diff --git a/src/targets/browser/browserPathResolver.ts b/src/targets/browser/browserPathResolver.ts index 0c39ed91e..bdf5347a1 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 { isURL, urlToRegex } from '../../common/urlUtils'; +import { isValidUrl, 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 (isURL(computedSourceRoot)) { + if (isValidUrl(computedSourceRoot)) { return new URL(url, computedSourceRoot).href; } return properResolve(computedSourceRoot, url); diff --git a/src/test/sources/sourcesTest.ts b/src/test/sources/sourcesTest.ts index e04bed112..62e9ae8b5 100644 --- a/src/test/sources/sourcesTest.ts +++ b/src/test/sources/sourcesTest.ts @@ -104,7 +104,7 @@ describe('sources', () => { itIntegrates('supports remote sources (#1424)', async ({ r }) => { const p = await r.launchUrlAndLoad('index.html'); - p.addScriptTag('remote-test/string.js'); + p.addScriptTag('remote-test/code.js'); const source = await p.waitForSource('string.ts'); await dumpSource(p, source, ''); diff --git a/src/test/testRunner.ts b/src/test/testRunner.ts index 84fd9b02d..b928ab494 100644 --- a/src/test/testRunner.ts +++ b/src/test/testRunner.ts @@ -80,16 +80,16 @@ export async function run(): Promise { } else { runner.addFile(join(__dirname, 'testIntegrationUtils')); runner.addFile(join(__dirname, 'infra/infra')); - runner.addFile(join(__dirname, 'breakpoints/breakpointsTest')); - runner.addFile(join(__dirname, 'browser/framesTest')); - runner.addFile(join(__dirname, 'browser/blazorSourcePathResolverTest')); - runner.addFile(join(__dirname, 'evaluate/evaluate')); - runner.addFile(join(__dirname, 'sources/sourcesTest')); - runner.addFile(join(__dirname, 'stacks/stacksTest')); - runner.addFile(join(__dirname, 'threads/threadsTest')); - runner.addFile(join(__dirname, 'variables/variablesTest')); + // runner.addFile(join(__dirname, 'breakpoints/breakpointsTest')); + // runner.addFile(join(__dirname, 'browser/framesTest')); + // runner.addFile(join(__dirname, 'browser/blazorSourcePathResolverTest')); + // runner.addFile(join(__dirname, 'evaluate/evaluate')); + // runner.addFile(join(__dirname, 'sources/sourcesTest')); + // runner.addFile(join(__dirname, 'stacks/stacksTest')); + // runner.addFile(join(__dirname, 'threads/threadsTest')); + // runner.addFile(join(__dirname, 'variables/variablesTest')); runner.addFile(join(__dirname, 'console/consoleFormatTest')); - runner.addFile(join(__dirname, 'console/consoleAPITest')); + // runner.addFile(join(__dirname, 'console/consoleAPITest')); const options = { cwd: __dirname }; const files = glob.sync('**/*.test.js', options); diff --git a/testWorkspace/web/remote-test/string.js b/testWorkspace/web/remote-test/code.js similarity index 100% rename from testWorkspace/web/remote-test/string.js rename to testWorkspace/web/remote-test/code.js diff --git a/testWorkspace/web/remote-test/string.js.map b/testWorkspace/web/remote-test/code.js.map similarity index 100% rename from testWorkspace/web/remote-test/string.js.map rename to testWorkspace/web/remote-test/code.js.map diff --git a/testWorkspace/web/remote-test/string.ts b/testWorkspace/web/remote-test/code.ts similarity index 100% rename from testWorkspace/web/remote-test/string.ts rename to testWorkspace/web/remote-test/code.ts From 65b2bccfe2f5ef615f318eb23a163861fbda0c8c Mon Sep 17 00:00:00 2001 From: d068544 Date: Mon, 17 Oct 2022 15:09:00 +0200 Subject: [PATCH 05/13] add more checks --- src/targets/node/nodeLauncher.ts | 4 ++-- src/test/testRunner.ts | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/targets/node/nodeLauncher.ts b/src/targets/node/nodeLauncher.ts index 2d0e12943..e73aedaa9 100644 --- a/src/targets/node/nodeLauncher.ts +++ b/src/targets/node/nodeLauncher.ts @@ -14,7 +14,7 @@ import { ILogger, LogTag } from '../../common/logging'; import { fixDriveLetterAndSlashes } from '../../common/pathUtils'; import { delay } from '../../common/promiseUtil'; import { ISourceMapMetadata } from '../../common/sourceMaps/sourceMap'; -import { absolutePathToFileUrl, urlToRegex } from '../../common/urlUtils'; +import { absolutePathToFileUrl, isAbsolute, urlToRegex } from '../../common/urlUtils'; import { AnyLaunchConfiguration, INodeLaunchConfiguration } from '../../configuration'; import { fixInspectFlags } from '../../ui/configurationUtils'; import { retryGetNodeEndpoint } from '../browser/spawn/endpoints'; @@ -260,7 +260,7 @@ export class NodeLauncher extends NodeLauncherBase { } const breakpointId = '(?:entryBreakpoint){0}'; - const breakpointPath = absolutePathToFileUrl(program); + const breakpointPath = isAbsolute(program) ? absolutePathToFileUrl(program) : program; const urlRegexp = urlToRegex(breakpointPath) + breakpointId; const breakpoint = await cdp.Debugger.setBreakpointByUrl({ urlRegex: urlRegexp, diff --git a/src/test/testRunner.ts b/src/test/testRunner.ts index b928ab494..84fd9b02d 100644 --- a/src/test/testRunner.ts +++ b/src/test/testRunner.ts @@ -80,16 +80,16 @@ export async function run(): Promise { } else { runner.addFile(join(__dirname, 'testIntegrationUtils')); runner.addFile(join(__dirname, 'infra/infra')); - // runner.addFile(join(__dirname, 'breakpoints/breakpointsTest')); - // runner.addFile(join(__dirname, 'browser/framesTest')); - // runner.addFile(join(__dirname, 'browser/blazorSourcePathResolverTest')); - // runner.addFile(join(__dirname, 'evaluate/evaluate')); - // runner.addFile(join(__dirname, 'sources/sourcesTest')); - // runner.addFile(join(__dirname, 'stacks/stacksTest')); - // runner.addFile(join(__dirname, 'threads/threadsTest')); - // runner.addFile(join(__dirname, 'variables/variablesTest')); + runner.addFile(join(__dirname, 'breakpoints/breakpointsTest')); + runner.addFile(join(__dirname, 'browser/framesTest')); + runner.addFile(join(__dirname, 'browser/blazorSourcePathResolverTest')); + runner.addFile(join(__dirname, 'evaluate/evaluate')); + runner.addFile(join(__dirname, 'sources/sourcesTest')); + runner.addFile(join(__dirname, 'stacks/stacksTest')); + runner.addFile(join(__dirname, 'threads/threadsTest')); + runner.addFile(join(__dirname, 'variables/variablesTest')); runner.addFile(join(__dirname, 'console/consoleFormatTest')); - // runner.addFile(join(__dirname, 'console/consoleAPITest')); + runner.addFile(join(__dirname, 'console/consoleAPITest')); const options = { cwd: __dirname }; const files = glob.sync('**/*.test.js', options); From 9d13e1c3476fd8626ae87bb269a9a4b3569b5478 Mon Sep 17 00:00:00 2001 From: d068544 Date: Mon, 17 Oct 2022 15:36:46 +0200 Subject: [PATCH 06/13] find traces --- src/adapter/threads.ts | 5 +++-- src/common/urlUtils.ts | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/adapter/threads.ts b/src/adapter/threads.ts index 0622f3a66..bbac0badd 100644 --- a/src/adapter/threads.ts +++ b/src/adapter/threads.ts @@ -1751,8 +1751,9 @@ export class Thread implements IVariableStoreLocationProvider { } const compiledSource = - this._sourceContainer.getSourceByOriginalUrl(urlUtils.absolutePathToFileUrl(chunk.path)) || - this._sourceContainer.getSourceByOriginalUrl(chunk.path); + this._sourceContainer.getSourceByOriginalUrl( + urlUtils.isAbsolute(chunk.path) ? urlUtils.absolutePathToFileUrl(chunk.path) : chunk.path, + ) || this._sourceContainer.getSourceByOriginalUrl(chunk.path); if (!compiledSource) { todo.push(chunk.toString()); continue; diff --git a/src/common/urlUtils.ts b/src/common/urlUtils.ts index 415b0b94c..0daf36b5f 100644 --- a/src/common/urlUtils.ts +++ b/src/common/urlUtils.ts @@ -301,11 +301,12 @@ export function fileUrlToNetworkPath(urlOrPath: string): string { // TODO: this does not escape/unescape special characters, but it should. export function absolutePathToFileUrl(absolutePath: string): string { - if (absolutePath.includes('://')) { - throw new Error( - `You are using the 'absolutePathToFileUrl()' on a string already containing a protocol: ${absolutePath}`, - ); + if (!isAbsolute(absolutePath)) { + // throw new Error( + // `You are using the 'absolutePathToFileUrl()' on a string which is not absolute: ${absolutePath}`, + // ); console.error('FE123' + absolutePath); + console.trace('FE456'); } if (platform === 'win32') { return 'file:///' + platformPathToUrlPath(absolutePath); From e9e323273f09ccb434886854c0f110c514d6bc6d Mon Sep 17 00:00:00 2001 From: d068544 Date: Mon, 17 Oct 2022 15:51:25 +0200 Subject: [PATCH 07/13] remove a few checks --- src/adapter/breakpoints/breakpointBase.ts | 8 ++------ src/targets/node/nodeLauncher.ts | 4 ++-- src/test/sources/sourcesTest.ts | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/adapter/breakpoints/breakpointBase.ts b/src/adapter/breakpoints/breakpointBase.ts index af881d999..8abc51a1b 100644 --- a/src/adapter/breakpoints/breakpointBase.ts +++ b/src/adapter/breakpoints/breakpointBase.ts @@ -4,7 +4,7 @@ import Cdp from '../../cdp/api'; import { LogTag } from '../../common/logging'; -import { absolutePathToFileUrl, isAbsolute, urlToRegex } from '../../common/urlUtils'; +import { absolutePathToFileUrl, urlToRegex } from '../../common/urlUtils'; import Dap from '../../dap/api'; import { BreakpointManager } from '../breakpoints'; import { base1To0, IUiLocation, Source, SourceFromMap, uiToRawOffset } from '../sources'; @@ -492,11 +492,7 @@ export abstract class Breakpoint { await this._setByUrl(thread, url, lineColumn); if (this.source.path !== url && this.source.path !== undefined) { - await this._setByUrl( - thread, - isAbsolute(this.source.path) ? absolutePathToFileUrl(this.source.path) : this.source.path, - lineColumn, - ); + await this._setByUrl(thread, absolutePathToFileUrl(this.source.path), lineColumn); } } } diff --git a/src/targets/node/nodeLauncher.ts b/src/targets/node/nodeLauncher.ts index e73aedaa9..2d0e12943 100644 --- a/src/targets/node/nodeLauncher.ts +++ b/src/targets/node/nodeLauncher.ts @@ -14,7 +14,7 @@ import { ILogger, LogTag } from '../../common/logging'; import { fixDriveLetterAndSlashes } from '../../common/pathUtils'; import { delay } from '../../common/promiseUtil'; import { ISourceMapMetadata } from '../../common/sourceMaps/sourceMap'; -import { absolutePathToFileUrl, isAbsolute, urlToRegex } from '../../common/urlUtils'; +import { absolutePathToFileUrl, urlToRegex } from '../../common/urlUtils'; import { AnyLaunchConfiguration, INodeLaunchConfiguration } from '../../configuration'; import { fixInspectFlags } from '../../ui/configurationUtils'; import { retryGetNodeEndpoint } from '../browser/spawn/endpoints'; @@ -260,7 +260,7 @@ export class NodeLauncher extends NodeLauncherBase { } const breakpointId = '(?:entryBreakpoint){0}'; - const breakpointPath = isAbsolute(program) ? absolutePathToFileUrl(program) : program; + const breakpointPath = absolutePathToFileUrl(program); const urlRegexp = urlToRegex(breakpointPath) + breakpointId; const breakpoint = await cdp.Debugger.setBreakpointByUrl({ urlRegex: urlRegexp, diff --git a/src/test/sources/sourcesTest.ts b/src/test/sources/sourcesTest.ts index 62e9ae8b5..0c35b28f0 100644 --- a/src/test/sources/sourcesTest.ts +++ b/src/test/sources/sourcesTest.ts @@ -106,7 +106,7 @@ describe('sources', () => { const p = await r.launchUrlAndLoad('index.html'); p.addScriptTag('remote-test/code.js'); - const source = await p.waitForSource('string.ts'); + const source = await p.waitForSource('code.ts'); await dumpSource(p, source, ''); p.assertLog(); From 6481e372bcd01bde3f6c6c5d932466c7b51054f3 Mon Sep 17 00:00:00 2001 From: d068544 Date: Mon, 17 Oct 2022 18:07:48 +0200 Subject: [PATCH 08/13] use string as file name for E2E testing --- src/test/sources/sourcesTest.ts | 4 ++-- testWorkspace/web/remote-test/code.js.map | 3 --- testWorkspace/web/remote-test/{code.js => string.js} | 0 testWorkspace/web/remote-test/string.js.map | 10 ++++++++++ testWorkspace/web/remote-test/{code.ts => string.ts} | 0 5 files changed, 12 insertions(+), 5 deletions(-) delete mode 100644 testWorkspace/web/remote-test/code.js.map rename testWorkspace/web/remote-test/{code.js => string.js} (100%) create mode 100644 testWorkspace/web/remote-test/string.js.map rename testWorkspace/web/remote-test/{code.ts => string.ts} (100%) diff --git a/src/test/sources/sourcesTest.ts b/src/test/sources/sourcesTest.ts index 0c35b28f0..e04bed112 100644 --- a/src/test/sources/sourcesTest.ts +++ b/src/test/sources/sourcesTest.ts @@ -104,9 +104,9 @@ describe('sources', () => { itIntegrates('supports remote sources (#1424)', async ({ r }) => { const p = await r.launchUrlAndLoad('index.html'); - p.addScriptTag('remote-test/code.js'); + p.addScriptTag('remote-test/string.js'); - const source = await p.waitForSource('code.ts'); + const source = await p.waitForSource('string.ts'); await dumpSource(p, source, ''); p.assertLog(); diff --git a/testWorkspace/web/remote-test/code.js.map b/testWorkspace/web/remote-test/code.js.map deleted file mode 100644 index d030a8466..000000000 --- a/testWorkspace/web/remote-test/code.js.map +++ /dev/null @@ -1,3 +0,0 @@ -{"version":3,"file":"string.js","sourceRoot":"http://localhost:8001/remote-test/","sources":["string.ts"],"names":[],"mappings":";AAAA,IAAI,CAAC,GAAG,CAAC,CAAC;AACV,CAAC,EAAE,CAAC;AACJ,QAAQ,CAAC;AACT,CAAC,EAAE,CAAC;AACJ,CAAC,EAAE,CAAC;AACJ,CAAC,EAAE,CAAC;AACJ,CAAC,EAAE,CAAC;AACJ,CAAC,EAAE,CAAC;AACJ,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC"} - - diff --git a/testWorkspace/web/remote-test/code.js b/testWorkspace/web/remote-test/string.js similarity index 100% rename from testWorkspace/web/remote-test/code.js rename to testWorkspace/web/remote-test/string.js diff --git a/testWorkspace/web/remote-test/string.js.map b/testWorkspace/web/remote-test/string.js.map new file mode 100644 index 000000000..4b92dbc7e --- /dev/null +++ b/testWorkspace/web/remote-test/string.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "string.js", + "sourceRoot": "http://localhost:8001/remote-test/", + "sources": [ + "string.ts" + ], + "names": [], + "mappings": ";AAAA,IAAI,CAAC,GAAG,CAAC,CAAC;AACV,CAAC,EAAE,CAAC;AACJ,QAAQ,CAAC;AACT,CAAC,EAAE,CAAC;AACJ,CAAC,EAAE,CAAC;AACJ,CAAC,EAAE,CAAC;AACJ,CAAC,EAAE,CAAC;AACJ,CAAC,EAAE,CAAC;AACJ,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC" +} \ No newline at end of file diff --git a/testWorkspace/web/remote-test/code.ts b/testWorkspace/web/remote-test/string.ts similarity index 100% rename from testWorkspace/web/remote-test/code.ts rename to testWorkspace/web/remote-test/string.ts From fb6d2b35d2ad99060dfc7aad4189efcb96884ce3 Mon Sep 17 00:00:00 2001 From: d068544 Date: Mon, 17 Oct 2022 18:10:51 +0200 Subject: [PATCH 09/13] let the method throw again --- src/common/urlUtils.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/common/urlUtils.ts b/src/common/urlUtils.ts index 0daf36b5f..3eb8f474c 100644 --- a/src/common/urlUtils.ts +++ b/src/common/urlUtils.ts @@ -302,11 +302,9 @@ export function fileUrlToNetworkPath(urlOrPath: string): string { // TODO: this does not escape/unescape special characters, but it should. export function absolutePathToFileUrl(absolutePath: string): string { if (!isAbsolute(absolutePath)) { - // throw new Error( - // `You are using the 'absolutePathToFileUrl()' on a string which is not absolute: ${absolutePath}`, - // ); - console.error('FE123' + absolutePath); - console.trace('FE456'); + throw new Error( + `You are using the 'absolutePathToFileUrl()' on a string which is not absolute: ${absolutePath}`, + ); } if (platform === 'win32') { return 'file:///' + platformPathToUrlPath(absolutePath); From 4dce9ceed8950f473c83438541af6d1b40668779 Mon Sep 17 00:00:00 2001 From: d068544 Date: Mon, 17 Oct 2022 18:28:04 +0200 Subject: [PATCH 10/13] fix windows issue --- src/adapter/resourceProvider/basicResourceProvider.ts | 2 +- src/targets/browser/browserPathResolver.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/adapter/resourceProvider/basicResourceProvider.ts b/src/adapter/resourceProvider/basicResourceProvider.ts index 318f9b136..392f83171 100644 --- a/src/adapter/resourceProvider/basicResourceProvider.ts +++ b/src/adapter/resourceProvider/basicResourceProvider.ts @@ -48,7 +48,7 @@ export class BasicResourceProvider implements IResourceProvider { return { ok: false, url, error, statusCode: 200 }; } } - + console.error('FE fetch url:' + url); return this.fetchHttp(url, cancellationToken, headers); } /** diff --git a/src/targets/browser/browserPathResolver.ts b/src/targets/browser/browserPathResolver.ts index bdf5347a1..d9dec9410 100644 --- a/src/targets/browser/browserPathResolver.ts +++ b/src/targets/browser/browserPathResolver.ts @@ -205,7 +205,7 @@ export class BrowserSourcePathResolver extends SourcePathResolverBase defaultPathMappingResolver, this.logger, ); - if (isValidUrl(computedSourceRoot)) { + if (isValidUrl(computedSourceRoot) && isValidUrl(url)) { return new URL(url, computedSourceRoot).href; } return properResolve(computedSourceRoot, url); From 9b009e4586c76b1ddc8c34856374398a24b3f8dd Mon Sep 17 00:00:00 2001 From: d068544 Date: Mon, 17 Oct 2022 18:46:04 +0200 Subject: [PATCH 11/13] add protocoll check --- src/common/urlUtils.ts | 5 +++-- src/targets/browser/browserPathResolver.ts | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/common/urlUtils.ts b/src/common/urlUtils.ts index 3eb8f474c..8ee9f7d4e 100644 --- a/src/common/urlUtils.ts +++ b/src/common/urlUtils.ts @@ -200,8 +200,9 @@ export function completeUrlEscapingRoot(base: string | undefined, relative: stri export function isValidUrl(url: string): boolean { try { - new URL(url); - return true; + const parsed = new URL(url); + + return parsed.protocol.toLowerCase() == 'http:' || parsed.protocol.toLowerCase() == 'https:'; } catch (e) { return false; } diff --git a/src/targets/browser/browserPathResolver.ts b/src/targets/browser/browserPathResolver.ts index d9dec9410..bdf5347a1 100644 --- a/src/targets/browser/browserPathResolver.ts +++ b/src/targets/browser/browserPathResolver.ts @@ -205,7 +205,7 @@ export class BrowserSourcePathResolver extends SourcePathResolverBase defaultPathMappingResolver, this.logger, ); - if (isValidUrl(computedSourceRoot) && isValidUrl(url)) { + if (isValidUrl(computedSourceRoot)) { return new URL(url, computedSourceRoot).href; } return properResolve(computedSourceRoot, url); From 6b54056e8b0c868686488f77200d7c5a4b3eaf81 Mon Sep 17 00:00:00 2001 From: d068544 Date: Mon, 17 Oct 2022 19:24:52 +0200 Subject: [PATCH 12/13] 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); From 5b24c306641bb0b0c2861dc7740c547c153d6c7d Mon Sep 17 00:00:00 2001 From: d068544 Date: Fri, 21 Oct 2022 13:43:05 +0200 Subject: [PATCH 13/13] remove log --- src/adapter/resourceProvider/basicResourceProvider.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/adapter/resourceProvider/basicResourceProvider.ts b/src/adapter/resourceProvider/basicResourceProvider.ts index 392f83171..64d5a5d2a 100644 --- a/src/adapter/resourceProvider/basicResourceProvider.ts +++ b/src/adapter/resourceProvider/basicResourceProvider.ts @@ -48,7 +48,6 @@ export class BasicResourceProvider implements IResourceProvider { return { ok: false, url, error, statusCode: 200 }; } } - console.error('FE fetch url:' + url); return this.fetchHttp(url, cancellationToken, headers); } /**