提交 e52382a0 编写于 作者: R Rob Lourens

findExecutable should check PATH in a case-insensitive way

Fix #109863
上级 e01e0ebe
......@@ -220,3 +220,9 @@ export function distinct(base: obj, target: obj): obj {
return result;
}
export function getCaseInsensitive(target: obj, key: string): any {
const lowercaseKey = key.toLowerCase();
const equivalentKey = Object.keys(target).find(k => k.toLowerCase() === lowercaseKey);
return equivalentKey ? target[equivalentKey] : target[key];
}
......@@ -212,4 +212,17 @@ suite('Objects', () => {
diff = objects.distinct(base, obj);
assert.deepEqual(diff, obj);
});
});
\ No newline at end of file
test('getCaseInsensitive', () => {
const obj1 = {
lowercase: 123,
mIxEdCaSe: 456
};
assert.equal(obj1.lowercase, objects.getCaseInsensitive(obj1, 'lowercase'));
assert.equal(obj1.lowercase, objects.getCaseInsensitive(obj1, 'lOwErCaSe'));
assert.equal(obj1.mIxEdCaSe, objects.getCaseInsensitive(obj1, 'MIXEDCASE'));
assert.equal(obj1.mIxEdCaSe, objects.getCaseInsensitive(obj1, 'mixedcase'));
});
});
......@@ -7,6 +7,7 @@ import { IProcessEnvironment, isLinux, isMacintosh, isWindows } from 'vs/base/co
import { readFile, exists } from 'vs/base/node/pfs';
import * as path from 'vs/base/common/path';
import { isString } from 'vs/base/common/types';
import { getCaseInsensitive } from 'vs/base/common/objects';
let mainProcessParentEnv: IProcessEnvironment | undefined;
......@@ -94,8 +95,9 @@ export async function findExecutable(command: string, cwd?: string, paths?: stri
const fullPath = path.join(cwd, command);
return await exists(fullPath) ? fullPath : undefined;
}
if (paths === undefined && isString(env.PATH)) {
paths = env.PATH.split(path.delimiter);
const envPath = getCaseInsensitive(env, 'PATH');
if (paths === undefined && isString(envPath)) {
paths = envPath.split(path.delimiter);
}
// No PATH environment. Make path absolute to the cwd.
if (paths === undefined || paths.length === 0) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册