Skip to content

Commit

Permalink
fix: allow webpacked path with special characters to map
Browse files Browse the repository at this point in the history
Fixes #1080
  • Loading branch information
connor4312 committed Oct 8, 2021
1 parent db28686 commit 491b548
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions src/common/sourceMaps/codeSearchStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/targets/browser/browserPathResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ export class BrowserSourcePathResolver extends SourcePathResolverBase<IOptions>
return undefined;
}

url = this.normalizeSourceMapUrl(url);

switch (this.vueMapper.getVueHandling(url)) {
case VueHandling.Omit:
return undefined;
Expand Down
3 changes: 1 addition & 2 deletions src/targets/node/nodeSourcePathResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ export class NodeSourcePathResolver extends SourcePathResolverBase<IOptions> {
* @override
*/
public async urlToAbsolutePath({ url, map }: IUrlResolution): Promise<string | undefined> {
// 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) ]
Expand Down
15 changes: 15 additions & 0 deletions src/targets/sourcePathResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export interface ISourcePathResolverOptions {
remoteRoot: string | null;
}

const nullByteRe = /\x00/;

export abstract class SourcePathResolverBase<T extends ISourcePathResolverOptions>
implements ISourcePathResolver
{
Expand Down Expand Up @@ -169,6 +171,19 @@ export abstract class SourcePathResolverBase<T extends ISourcePathResolverOption
return remotePath;
}

/**
* Normalizes a source map URL for further processing. Should be called
* before introspecting a URL included with a sourcemap.
*/
protected normalizeSourceMapUrl(url: string) {
// https://github.com/microsoft/vscode-js-debug/issues/529
url = url.replace(/\?.+/, '');
// https://github.com/microsoft/vscode-js-debug/issues/1080#issuecomment-938200168
url = url.replace(nullByteRe, '');

return url;
}

private canMapPath(candidate: string) {
return (
path.posix.isAbsolute(candidate) || path.win32.isAbsolute(candidate) || isFileUrl(candidate)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
allThreadsStopped : false
description : Paused on breakpoint
reason : breakpoint
threadId : <number>
}
<anonymous> @ ${workspaceFolder}/webpackNulByte/src/#hello/world.ts:1:1
13 changes: 13 additions & 0 deletions src/test/breakpoints/breakpointsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
});
});
10 changes: 10 additions & 0 deletions testWorkspace/webpackNulByte/build/greeter.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions testWorkspace/webpackNulByte/build/greeter.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions testWorkspace/webpackNulByte/src/#hello/world.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('hello world');

0 comments on commit 491b548

Please sign in to comment.