Skip to content

Commit 9d7e7b9

Browse files
committed
fix(@angular/cli): ignore relative entries when resolving executables on PATH
1 parent 7d94382 commit 9d7e7b9

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

packages/angular/cli/src/utilities/executable.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import { existsSync } from 'node:fs';
10-
import { delimiter, extname, join } from 'node:path';
10+
import { delimiter, extname, isAbsolute, join } from 'node:path';
1111

1212
/**
1313
* Searches the `PATH` environment variable for a given executable binary name.
@@ -40,6 +40,9 @@ export function findExecutableOnPath(binaryName: string): string | undefined {
4040
}
4141

4242
const dir = rawDir.startsWith('"') && rawDir.endsWith('"') ? rawDir.slice(1, -1) : rawDir;
43+
if (!isAbsolute(dir)) {
44+
continue;
45+
}
4346

4447
for (const ext of extensions) {
4548
const candidate = join(dir, binaryName + ext);

packages/angular/cli/src/utilities/executable_spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,15 @@ describe('findExecutableOnPath', () => {
3838
process.env.PATH = originalPath;
3939
}
4040
});
41+
42+
it('should ignore relative PATH entries', () => {
43+
const originalPath = process.env.PATH;
44+
try {
45+
process.env.PATH = '.';
46+
const resolved = findExecutableOnPath('node');
47+
expect(resolved).toBeUndefined();
48+
} finally {
49+
process.env.PATH = originalPath;
50+
}
51+
});
4152
});

0 commit comments

Comments
 (0)