@@ -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 ( / ^ P A T H $ / 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