Skip to content

Commit cdca7f2

Browse files
authored
Merge pull request #2171 from microsoft/connor4312/1.97.1-cherry-pick
1.97.1 cherry pick
2 parents c0bd8c0 + e00e62c commit cdca7f2

File tree

5 files changed

+69
-13
lines changed

5 files changed

+69
-13
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ Nothing, yet
88

99
## 1.97 (January 2025)
1010

11+
### 1.97.1
12+
13+
- fix: don't look for binaries outside the workspace folder ([vscode#240407](https://github.com/microsoft/vscode/issues/240407))
14+
15+
### 1.97.0
16+
1117
- fix: allow pretty printing sources when not paused ([#2138](https://github.com/microsoft/vscode-js-debug/issues/2138))
1218
- fix: breakpoints not registered in transpiled file in remoteRoot ([#2122](https://github.com/microsoft/vscode-js-debug/issues/2122))
1319
- fix: content verification of files in Node.js failing with UTF-8 BOM

src/targets/node/nodeBinaryProvider.test.ts

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import { join } from 'path';
88
import { SinonStub, stub } from 'sinon';
99
import { EnvironmentVars } from '../../common/environmentVars';
1010
import { Logger } from '../../common/logging/logger';
11+
import { upcastPartial } from '../../common/objUtils';
1112
import { Semver } from '../../common/semver';
13+
import { AnyLaunchConfiguration } from '../../configuration';
1214
import { ErrorCodes } from '../../dap/errors';
1315
import { ProtocolError } from '../../dap/protocolError';
1416
import { Capability, NodeBinary, NodeBinaryProvider } from '../../targets/node/nodeBinaryProvider';
@@ -20,6 +22,8 @@ describe('NodeBinaryProvider', function() {
2022
this.timeout(30 * 1000); // windows lookups in CI seem to be very slow sometimes
2123

2224
let p: NodeBinaryProvider;
25+
let dir: string;
26+
2327
const env = (name: string) =>
2428
EnvironmentVars.empty.addToPath(join(testWorkspace, 'nodePathProvider', name));
2529
const binaryLocation = (name: string, binary = 'node') =>
@@ -33,11 +37,17 @@ describe('NodeBinaryProvider', function() {
3337
let packageJson: IPackageJsonProvider;
3438

3539
beforeEach(() => {
40+
dir = getTestDir();
3641
packageJson = {
3742
getPath: () => Promise.resolve(undefined),
3843
getContents: () => Promise.resolve(undefined),
3944
};
40-
p = new NodeBinaryProvider(Logger.null, fsPromises, packageJson);
45+
p = new NodeBinaryProvider(
46+
Logger.null,
47+
fsPromises,
48+
packageJson,
49+
upcastPartial<AnyLaunchConfiguration>({ __workspaceFolder: dir }),
50+
);
4151
});
4252

4353
it('rejects not found', async () => {
@@ -198,8 +208,38 @@ describe('NodeBinaryProvider', function() {
198208
});
199209
});
200210

211+
it('does not recurse upwards past workspace folder', async () => {
212+
const cwd = join(dir, 'subdir');
213+
p = new NodeBinaryProvider(
214+
Logger.null,
215+
fsPromises,
216+
packageJson,
217+
upcastPartial<AnyLaunchConfiguration>({ __workspaceFolder: cwd }),
218+
);
219+
await fsPromises.mkdir(cwd, { recursive: true });
220+
221+
createFileTree(dir, {
222+
'node_modules/.bin': {
223+
'node.exe': '',
224+
node: '',
225+
},
226+
});
227+
228+
try {
229+
const r = await p.resolveAndValidate(
230+
EnvironmentVars.empty.update('PATHEXT', '.EXE'),
231+
'node',
232+
undefined,
233+
cwd,
234+
);
235+
console.log(r);
236+
} catch (err) {
237+
expect(err).to.be.an.instanceOf(ProtocolError);
238+
expect(err.cause.id).to.equal(ErrorCodes.CannotFindNodeBinary);
239+
}
240+
});
241+
201242
it('automatically finds programs in node_modules/.bin', async () => {
202-
const dir = getTestDir();
203243
createFileTree(dir, {
204244
'node_modules/.bin': {
205245
'mocha.cmd': '',

src/targets/node/nodeBinaryProvider.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ import type * as vscodeType from 'vscode';
99
import { EnvironmentVars } from '../../common/environmentVars';
1010
import { existsInjected } from '../../common/fsUtils';
1111
import { ILogger, LogTag } from '../../common/logging';
12-
import { findExecutable, findInPath } from '../../common/pathUtils';
12+
import { findExecutable, findInPath, isSubpathOrEqualTo } from '../../common/pathUtils';
1313
import { spawnAsync } from '../../common/processUtils';
1414
import { Semver } from '../../common/semver';
1515
import { getNormalizedBinaryName, nearestDirectoryWhere } from '../../common/urlUtils';
16+
import { AnyLaunchConfiguration } from '../../configuration';
1617
import {
1718
cannotFindNodeBinary,
1819
cwdDoesNotExist,
@@ -220,6 +221,7 @@ export class NodeBinaryProvider implements INodeBinaryProvider {
220221
@inject(ILogger) private readonly logger: ILogger,
221222
@inject(FS) private readonly fs: FsPromises,
222223
@inject(IPackageJsonProvider) private readonly packageJson: IPackageJsonProvider,
224+
@inject(AnyLaunchConfiguration) private readonly launchConfig: Partial<AnyLaunchConfiguration>,
223225
) {}
224226

225227
/**
@@ -263,9 +265,17 @@ export class NodeBinaryProvider implements INodeBinaryProvider {
263265
return undefined;
264266
}
265267

268+
const workspaceFolder = this.launchConfig.__workspaceFolder;
269+
if (!workspaceFolder) {
270+
return undefined;
271+
}
272+
266273
return nearestDirectoryWhere(
267274
cwd,
268-
dir => findExecutable(this.fs, join(dir, 'node_modules', '.bin', executable), env),
275+
dir =>
276+
!isSubpathOrEqualTo(workspaceFolder, dir)
277+
? Promise.resolve(undefined)
278+
: findExecutable(this.fs, join(dir, 'node_modules', '.bin', executable), env),
269279
);
270280
}
271281

@@ -391,9 +401,10 @@ export class InteractiveNodeBinaryProvider extends NodeBinaryProvider {
391401
@inject(ILogger) logger: ILogger,
392402
@inject(FS) fs: FsPromises,
393403
@inject(IPackageJsonProvider) packageJson: IPackageJsonProvider,
404+
@inject(AnyLaunchConfiguration) launchConfig: Partial<AnyLaunchConfiguration>,
394405
@optional() @inject(VSCodeApi) private readonly vscode: typeof vscodeType | undefined,
395406
) {
396-
super(logger, fs, packageJson);
407+
super(logger, fs, packageJson, launchConfig);
397408
}
398409

399410
/**

src/ui/autoAttach.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,21 @@ export function registerAutoAttach(
3434

3535
const launcher = (async () => {
3636
const logger = new ProxyLogger();
37+
let config = readConfig(vscode.workspace, Configuration.TerminalDebugConfig);
38+
if (workspaceFolder) {
39+
const fsPath = workspaceFolder?.uri.fsPath;
40+
config = { ...config, cwd: fsPath, __workspaceFolder: fsPath };
41+
}
3742
// TODO: Figure out how to inject FsUtils
3843
const inst = new AutoAttachLauncher(
39-
new NodeBinaryProvider(logger, services.get(FS), noPackageJsonProvider),
44+
new NodeBinaryProvider(logger, services.get(FS), noPackageJsonProvider, config || {}),
4045
logger,
4146
context,
4247
services.get(FS),
4348
services.get(NodeOnlyPathResolverFactory),
4449
services.get(IPortLeaseTracker),
4550
);
4651

47-
let config = readConfig(vscode.workspace, Configuration.TerminalDebugConfig);
48-
if (workspaceFolder) {
49-
const fsPath = workspaceFolder?.uri.fsPath;
50-
config = { ...config, cwd: fsPath, __workspaceFolder: fsPath };
51-
}
52-
5352
await launchVirtualTerminalParent(delegate, inst, config);
5453

5554
inst.onTargetListChanged(() => {

src/ui/debugTerminalUI.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ export function registerDebugTerminalUI(
258258
const logger = new ProxyLogger();
259259
const launcher = createLauncherFn(
260260
logger,
261-
new NodeBinaryProvider(logger, services.get(FS), noPackageJsonProvider),
261+
new NodeBinaryProvider(logger, services.get(FS), noPackageJsonProvider, {}),
262262
);
263263

264264
launcher.onTerminalCreated(terminal => {

0 commit comments

Comments
 (0)