mirror of
https://github.com/textmate/textmate.git
synced 2026-01-21 04:38:13 -05:00
Whitelist rather than blacklist inherited variables
Initially the environment was clean but it was found that some variables should be inherited, e.g. SSH_AUTH_SOCK. Therefor a blacklist was introduced, but it seems futile trying to keep it updated with all the variables that may affect the behavior of commands executed from within TextMate, therefor we now use a whitelist. Probably the whitelist should be user configurable as launchd uses environment variables to communicate dynamically allocated sockets (like SSH_AUTH_SOCK, but there are also some Apple-prefixed variables pointing to named sockets). Issue #238.
This commit is contained in:
@@ -5,15 +5,10 @@
|
||||
|
||||
namespace oak
|
||||
{
|
||||
static bool exclude_variable (std::string const& variable)
|
||||
static bool include_variable (std::string const& variable)
|
||||
{
|
||||
static std::string const BlackListedPrefixes[] = { "TM_", "OAK_", "DIALOG", "MAKE", "MFLAGS", "GIT_" };
|
||||
iterate(prefix, BlackListedPrefixes)
|
||||
{
|
||||
if(variable.find(*prefix) == 0)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
static std::set<std::string> const WhiteListedVariables = { "COMMAND_MODE", "SHELL", "SHLVL", "SSH_AUTH_SOCK", "__CF_USER_TEXT_ENCODING" };
|
||||
return variable.find("Apple") == 0 || WhiteListedVariables.find(variable) != WhiteListedVariables.end();
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> setup_basic_environment ()
|
||||
@@ -32,7 +27,7 @@ namespace oak
|
||||
for(char** pair = *envPtr; pair && *pair; ++pair)
|
||||
{
|
||||
char* value = strchr(*pair, '=');
|
||||
if(value && *value == '=' && !exclude_variable(std::string(*pair, value)))
|
||||
if(value && *value == '=' && include_variable(std::string(*pair, value)))
|
||||
res[std::string(*pair, value)] = value + 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user