mirror of
https://github.com/fish-shell/fish-shell
synced 2024-11-11 23:47:25 +00:00
Prefer the first, not last, of any env var duplicates
If envp contains duplicate environment variables, use the first value, not the last value. Fixes #2784.
This commit is contained in:
parent
1e7c3fe709
commit
3044697baa
1 changed files with 9 additions and 5 deletions
14
src/env.cpp
14
src/env.cpp
|
@ -449,12 +449,16 @@ void env_init(const struct config_paths_t *paths /* or NULL */)
|
|||
is to insert valid data
|
||||
*/
|
||||
|
||||
/*
|
||||
Import environment variables
|
||||
*/
|
||||
for (char **p = (environ ? environ : __environ); p && *p; p++)
|
||||
/* Import environment variables. Walk backwards so that the first one out of any duplicates wins (#2784) */
|
||||
const char * const * envp = (environ ? environ : __environ);
|
||||
size_t i = 0;
|
||||
while (envp && envp[i])
|
||||
{
|
||||
const wcstring key_and_val = str2wcstring(*p); //like foo=bar
|
||||
i++;
|
||||
}
|
||||
while (i--)
|
||||
{
|
||||
const wcstring key_and_val = str2wcstring(envp[i]); //like foo=bar
|
||||
size_t eql = key_and_val.find(L'=');
|
||||
if (eql == wcstring::npos)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue