Fix Regression In #12317 For zsh

In Atom 1.7 and 1.8, the environment would be patched for users of the zsh shell on OS X. A whitelist of shells was established in #12317, which is extended here.
This commit is contained in:
Joe Fitzgerald
2016-08-11 12:45:02 -06:00
parent 727d3d76d5
commit b7a48967fa
3 changed files with 64 additions and 5 deletions

View File

@@ -2,7 +2,7 @@
/* eslint-env jasmine */
import child_process from 'child_process'
import updateProcessEnv from '../src/update-process-env'
import {updateProcessEnv, shellShouldBePatched} from '../src/update-process-env'
import dedent from 'dedent'
describe('updateProcessEnv(launchEnv)', function () {
@@ -84,5 +84,41 @@ describe('updateProcessEnv(launchEnv)', function () {
expect(process.env).toEqual({FOO: 'bar'})
})
})
describe('shells on osx', function () {
it('shellShouldBePatched() returns the shell when the shell should be patched', function () {
process.platform = 'darwin'
let shellsToTest = new Set([
'/bin/sh',
'/usr/local/bin/sh',
'/bin/bash',
'/usr/local/bin/bash',
'/bin/zsh',
'/usr/local/bin/zsh',
'/bin/fish',
'/usr/local/bin/fish'
])
for (let shell of shellsToTest) {
process.env.SHELL = shell
expect(shellShouldBePatched()).toBe(shell)
}
})
it('shellShouldBePatched() returns false when the shell should not be patched', function () {
process.platform = 'darwin'
let shellsToTest = new Set([
'/bin/unsupported',
'/bin/shh',
'/bin/tcsh',
'/usr/csh'
])
for (let shell of shellsToTest) {
process.env.SHELL = shell
let result = shellShouldBePatched()
console.log(result)
expect(result).toBe(false)
}
})
})
})
})

View File

@@ -1,6 +1,6 @@
# Like sands through the hourglass, so are the days of our lives.
module.exports = ({blobStore}) ->
updateProcessEnv = require('./update-process-env')
{updateProcessEnv} = require('./update-process-env')
path = require 'path'
require './window'
{getWindowLoadSettings} = require './window-load-settings-helpers'

View File

@@ -8,7 +8,14 @@ const ENVIRONMENT_VARIABLES_TO_PRESERVE = new Set([
'ATOM_HOME'
])
export default function updateProcessEnv (launchEnv) {
const OSX_SHELLS_TO_PATCH = new Set([
'/sh',
'/bash',
'/zsh',
'/fish'
])
function updateProcessEnv (launchEnv) {
let envToAssign
if (launchEnv && launchEnv.PWD) {
envToAssign = launchEnv
@@ -33,9 +40,23 @@ export default function updateProcessEnv (launchEnv) {
}
}
function getEnvFromShell () {
function shellShouldBePatched () {
let shell = process.env.SHELL
if (shell && (shell.endsWith('/bash') || shell.endsWith('/sh'))) {
if (!shell) {
return false
}
for (let s of OSX_SHELLS_TO_PATCH) {
if (shell.endsWith(s)) {
return shell
}
}
return false
}
function getEnvFromShell () {
let shell = shellShouldBePatched()
if (shell) {
let {stdout} = spawnSync(shell, ['-ilc', 'command env'], {encoding: 'utf8'})
if (stdout) {
let result = {}
@@ -51,3 +72,5 @@ function getEnvFromShell () {
}
}
}
export default { updateProcessEnv, shellShouldBePatched }