Skip to content

Commit fa0438c

Browse files
committed
(GH-400) Fix Path environment parsing for Ruby Helper
Previously the RubyHelper manipulates the path environment however due to Object property names being case sensitive it could simply be that it's called Path or path, particularly on Windows not so much on Linux etc.. It's also possible that there is no PATH set but unlikely. This commit changes the Path processing be to case-insensitive and force it to be called PATH This commit also removes environment variables whose value is set to null or undefined.
1 parent ed2d96e commit fa0438c

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/rubyHelper.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,20 @@ export class RubyHelper {
3030
break;
3131
}
3232

33-
if (spawn_options.env.PATH === undefined) { spawn_options.env.PATH = ''; }
33+
if (spawn_options.env.PATH === undefined) {
34+
// It's possible that there is no PATH set but unlikely. Due to Object property names being
35+
// case sensitive it could simply be that it's called Path or path, particularly on Windows
36+
// not so much on Linux etc.. Look through all of the environment names looking for PATH in a
37+
// case insensitive way and remove the conflicting env var.
38+
let envPath: string = '';
39+
Object.keys(spawn_options.env).forEach(function(keyname) {
40+
if (keyname.match(/^PATH$/i)) {
41+
envPath = spawn_options.env[keyname];
42+
spawn_options.env[keyname] = undefined;
43+
}
44+
});
45+
spawn_options.env.PATH = envPath;
46+
}
3447
if (spawn_options.env.RUBYLIB === undefined) { spawn_options.env.RUBYLIB = ''; }
3548

3649
let command = '';
@@ -68,14 +81,27 @@ export class RubyHelper {
6881
logger.debug(logPrefix + 'Using environment variable GEM_PATH=' + spawn_options.env.GEM_PATH);
6982
logger.debug(logPrefix + 'Using environment variable GEM_HOME=' + spawn_options.env.GEM_HOME);
7083

84+
// undefined or null values still appear in the child spawn environment variables
85+
// In this case these elements should be removed from the Object
86+
this.removeEmptyElements(spawn_options.env);
87+
7188
let result = {
7289
command: command,
7390
args : [rubyFile],
7491
options: spawn_options
7592
};
7693

7794
return result;
95+
}
7896

97+
private static removeEmptyElements(obj: Object) {
98+
const propNames = Object.getOwnPropertyNames(obj);
99+
for (var i = 0; i < propNames.length; i++) {
100+
const propName = propNames[i];
101+
if (obj[propName] === null || obj[propName] === undefined) {
102+
delete obj[propName];
103+
}
104+
}
79105
}
80106

81107
private static shallowCloneObject(value:Object): Object {

0 commit comments

Comments
 (0)