Merge pull request #11489 from atom/ld-fix-case-insensitive-env

Preserve the process.env magic for Windows
This commit is contained in:
Lee Dohm
2016-04-15 17:13:41 -07:00

View File

@@ -67,9 +67,20 @@ function needsPatching (options = { platform: process.platform, env: process.env
return false
}
// Fix for #11302 because `process.env` on Windows is a magic object that offers case-insensitive
// environment variable matching. By always cloning to `process.env` we prevent breaking the
// underlying functionality.
function clone (to, from) {
for (var key in to) {
delete to[key]
}
Object.assign(to, from)
}
function normalize (options = {}) {
if (options && options.env) {
process.env = options.env
clone(process.env, options.env)
}
if (!options.env) {
@@ -85,8 +96,8 @@ function normalize (options = {}) {
// in #4126. Retain the original in case someone needs it.
let shellEnv = getFromShell()
if (shellEnv && shellEnv.PATH) {
process._originalEnv = process.env
process.env = shellEnv
process._originalEnv = Object.assign({}, process.env)
clone(process.env, shellEnv)
}
}
}
@@ -96,7 +107,7 @@ function replace (env) {
return
}
process.env = env
clone(process.env, env)
}
export default { getFromShell, needsPatching, normalize, replace }