From 491b5482945bba4d71cd5a9c150caa5cb1afba83 Mon Sep 17 00:00:00 2001 From: Connor Peet Date: Fri, 8 Oct 2021 09:15:15 -0700 Subject: [PATCH] fix: allow webpacked path with special characters to map Fixes #1080 --- CHANGELOG.md | 1 + src/common/sourceMaps/codeSearchStrategy.ts | 6 +++--- src/targets/browser/browserPathResolver.ts | 2 ++ src/targets/node/nodeSourcePathResolver.ts | 3 +-- src/targets/sourcePathResolver.ts | 15 +++++++++++++++ ...eakpoints-normalizes-webpack-nul-byte-1080.txt | 7 +++++++ src/test/breakpoints/breakpointsTest.ts | 13 +++++++++++++ testWorkspace/webpackNulByte/build/greeter.js | 10 ++++++++++ testWorkspace/webpackNulByte/build/greeter.js.map | 1 + testWorkspace/webpackNulByte/src/#hello/world.ts | 1 + 10 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 src/test/breakpoints/breakpoints-normalizes-webpack-nul-byte-1080.txt create mode 100644 testWorkspace/webpackNulByte/build/greeter.js create mode 100644 testWorkspace/webpackNulByte/build/greeter.js.map create mode 100644 testWorkspace/webpackNulByte/src/#hello/world.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 93fdf9b17..120a52b0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ This changelog records changes to stable releases since 1.50.2. "TBA" changes he ## Nightly Only - fix: update path handling when debugging vscode webviews ([ref](https://github.com/microsoft/vscode/issues/133867)) +- fix: allow webpacked path with special characters to map ([#1080](https://github.com/microsoft/vscode-js-debug/issues/1080)) ## v1.61 (September 2021) diff --git a/src/common/sourceMaps/codeSearchStrategy.ts b/src/common/sourceMaps/codeSearchStrategy.ts index be48a3050..052131dc6 100644 --- a/src/common/sourceMaps/codeSearchStrategy.ts +++ b/src/common/sourceMaps/codeSearchStrategy.ts @@ -2,14 +2,14 @@ * Copyright (C) Microsoft Corporation. All rights reserved. *--------------------------------------------------------*/ +import { injectable } from 'inversify'; import type * as vscodeType from 'vscode'; -import { LogTag, ILogger } from '../logging'; +import { FileGlobList } from '../fileGlobList'; +import { ILogger, LogTag } from '../logging'; import { forceForwardSlashes } from '../pathUtils'; import { NodeSearchStrategy } from './nodeSearchStrategy'; import { ISourceMapMetadata } from './sourceMap'; import { createMetadataForFile, ISearchStrategy } from './sourceMapRepository'; -import { injectable } from 'inversify'; -import { FileGlobList } from '../fileGlobList'; /** * A source map repository that uses VS Code's proposed search API to diff --git a/src/targets/browser/browserPathResolver.ts b/src/targets/browser/browserPathResolver.ts index 61f5d36a9..ea5ebc6e3 100644 --- a/src/targets/browser/browserPathResolver.ts +++ b/src/targets/browser/browserPathResolver.ts @@ -153,6 +153,8 @@ export class BrowserSourcePathResolver extends SourcePathResolverBase return undefined; } + url = this.normalizeSourceMapUrl(url); + switch (this.vueMapper.getVueHandling(url)) { case VueHandling.Omit: return undefined; diff --git a/src/targets/node/nodeSourcePathResolver.ts b/src/targets/node/nodeSourcePathResolver.ts index 7c6adc79b..14c57b845 100644 --- a/src/targets/node/nodeSourcePathResolver.ts +++ b/src/targets/node/nodeSourcePathResolver.ts @@ -69,8 +69,7 @@ export class NodeSourcePathResolver extends SourcePathResolverBase { * @override */ public async urlToAbsolutePath({ url, map }: IUrlResolution): Promise { - // replace any query string, which can be generated by webpack bundles - url = url.replace(/\?.+/, ''); + url = this.normalizeSourceMapUrl(url); // Allow debugging of externally loaded Node internals // [ by building Node with ./configure --node-builtin-modules-path $(pwd) ] diff --git a/src/targets/sourcePathResolver.ts b/src/targets/sourcePathResolver.ts index 1e4f0e72d..008419ad9 100644 --- a/src/targets/sourcePathResolver.ts +++ b/src/targets/sourcePathResolver.ts @@ -32,6 +32,8 @@ export interface ISourcePathResolverOptions { remoteRoot: string | null; } +const nullByteRe = /\x00/; + export abstract class SourcePathResolverBase implements ISourcePathResolver { @@ -169,6 +171,19 @@ export abstract class SourcePathResolverBase +} + @ ${workspaceFolder}/webpackNulByte/src/#hello/world.ts:1:1 diff --git a/src/test/breakpoints/breakpointsTest.ts b/src/test/breakpoints/breakpointsTest.ts index dd2b756dd..94618f497 100644 --- a/src/test/breakpoints/breakpointsTest.ts +++ b/src/test/breakpoints/breakpointsTest.ts @@ -1015,4 +1015,17 @@ describe('breakpoints', () => { handle.assertLog({ process: removeNodeInternalsStackLines }); }); + + itIntegrates('normalizes webpack nul byte (#1080)', async ({ r }) => { + const cwd = join(testWorkspace, 'webpackNulByte'); + const handle = await r.runScript(join(cwd, 'build/greeter.js'), { cwd }); + await handle.dap.setBreakpoints({ + source: { path: join(cwd, 'src/#hello/world.ts') }, + breakpoints: [{ line: 1, column: 0 }], + }); + + handle.load(); + await waitForPause(handle); + handle.assertLog({ substring: true }); + }); }); diff --git a/testWorkspace/webpackNulByte/build/greeter.js b/testWorkspace/webpackNulByte/build/greeter.js new file mode 100644 index 000000000..0053fc71b --- /dev/null +++ b/testWorkspace/webpackNulByte/build/greeter.js @@ -0,0 +1,10 @@ +/******/ (() => { // webpackBootstrap +var __webpack_exports__ = {}; +/*!******************************!*\ + !*** ./src/#hello/world.ts ***! + \******************************/ +console.log('hello world'); + +/******/ })() +; +//# sourceMappingURL=greeter.js.map diff --git a/testWorkspace/webpackNulByte/build/greeter.js.map b/testWorkspace/webpackNulByte/build/greeter.js.map new file mode 100644 index 000000000..3d35e01ff --- /dev/null +++ b/testWorkspace/webpackNulByte/build/greeter.js.map @@ -0,0 +1 @@ +{"version":3,"file":"greeter.js","mappings":";;;;;AAAA,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC","sources":["webpack://bug-breakpoint/./src/\u0000#hello/world.ts"],"sourcesContent":["console.log('hello world');\n"],"names":[],"sourceRoot":""} \ No newline at end of file diff --git a/testWorkspace/webpackNulByte/src/#hello/world.ts b/testWorkspace/webpackNulByte/src/#hello/world.ts new file mode 100644 index 000000000..6be02374d --- /dev/null +++ b/testWorkspace/webpackNulByte/src/#hello/world.ts @@ -0,0 +1 @@ +console.log('hello world');