Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b800388

Browse files
committed
Fix env override regression, fixes #3820
1 parent dfd04a9 commit b800388

7 files changed

Lines changed: 16 additions & 6 deletions

File tree

src/Composer/Command/CreateProjectCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,8 @@ protected function installRootPackage(IOInterface $io, Config $config, $packageN
316316
$io->writeError('<info>Created project in ' . $directory . '</info>');
317317
chdir($directory);
318318

319-
putenv('COMPOSER_ROOT_VERSION='.$package->getPrettyVersion());
319+
$_SERVER['COMPOSER_ROOT_VERSION'] = $package->getPrettyVersion();
320+
putenv('COMPOSER_ROOT_VERSION='.$_SERVER['COMPOSER_ROOT_VERSION']);
320321

321322
return $installedFromVcs;
322323
}

src/Composer/Command/RunScriptCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
8787
// add the bin dir to the PATH to make local binaries of deps usable in scripts
8888
$binDir = $composer->getConfig()->get('bin-dir');
8989
if (is_dir($binDir)) {
90-
putenv('PATH='.realpath($binDir).PATH_SEPARATOR.getenv('PATH'));
90+
$_SERVER['PATH'] = realpath($binDir).PATH_SEPARATOR.getenv('PATH');
91+
putenv('PATH='.$_SERVER['PATH']);
9192
}
9293

9394
$args = $input->getArgument('args');

src/Composer/Command/ScriptAliasCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
5757
// add the bin dir to the PATH to make local binaries of deps usable in scripts
5858
$binDir = $composer->getConfig()->get('bin-dir');
5959
if (is_dir($binDir)) {
60-
putenv('PATH='.realpath($binDir).PATH_SEPARATOR.getenv('PATH'));
60+
$_SERVER['PATH'] = realpath($binDir).PATH_SEPARATOR.getenv('PATH');
61+
putenv('PATH='.$_SERVER['PATH']);
6162
}
6263

6364
$args = $input->getArguments();

src/Composer/Util/Git.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,18 +164,22 @@ public static function cleanEnv()
164164
// added in git 1.7.1, prevents prompting the user for username/password
165165
if (getenv('GIT_ASKPASS') !== 'echo') {
166166
putenv('GIT_ASKPASS=echo');
167+
unset($_SERVER['GIT_ASKPASS']);
167168
}
168169

169170
// clean up rogue git env vars in case this is running in a git hook
170171
if (getenv('GIT_DIR')) {
171172
putenv('GIT_DIR');
173+
unset($_SERVER['GIT_DIR']);
172174
}
173175
if (getenv('GIT_WORK_TREE')) {
174176
putenv('GIT_WORK_TREE');
177+
unset($_SERVER['GIT_WORK_TREE']);
175178
}
176179

177180
// clean up env for OSX, see https://github.com/composer/composer/issues/2146#issuecomment-35478940
178181
putenv("DYLD_LIBRARY_PATH");
182+
unset($_SERVER['DYLD_LIBRARY_PATH']);
179183
}
180184

181185
public static function getGitHubDomainsRegex(Config $config)

src/Composer/Util/ProcessExecutor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function execute($command, &$output = null, $cwd = null)
5656

5757
$this->captureOutput = count(func_get_args()) > 1;
5858
$this->errorOutput = null;
59-
$process = new Process($command, $cwd, array('LANGUAGE' => 'C') + $_ENV + $_SERVER, null, static::getTimeout());
59+
$process = new Process($command, $cwd, array_replace($_ENV, $_SERVER, array('LANGUAGE' => 'C')), null, static::getTimeout());
6060

6161
$callback = is_callable($output) ? $output : array($this, 'outputHandler');
6262
$process->run($callback);

src/Composer/Util/Svn.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public static function cleanEnv()
8181
{
8282
// clean up env for OSX, see https://github.com/composer/composer/issues/2146#issuecomment-35478940
8383
putenv("DYLD_LIBRARY_PATH");
84+
unset($_SERVER['DYLD_LIBRARY_PATH']);
8485
}
8586

8687
/**

tests/Composer/Test/AllFunctionalTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ public function tearDown()
4242
}
4343
if ($this->oldenv) {
4444
$fs->removeDirectory(getenv('COMPOSER_HOME'));
45-
putenv('COMPOSER_HOME='.$this->oldenv);
45+
$_SERVER['COMPOSER_HOME'] = $this->oldenv;
46+
putenv('COMPOSER_HOME='.$_SERVER['COMPOSER_HOME']);
4647
$this->oldenv = null;
4748
}
4849
}
@@ -86,7 +87,8 @@ public function testIntegration(\SplFileInfo $testFile)
8687
$testData = $this->parseTestFile($testFile);
8788

8889
$this->oldenv = getenv('COMPOSER_HOME');
89-
putenv('COMPOSER_HOME='.$this->testDir.'home');
90+
$_SERVER['COMPOSER_HOME'] = $this->testDir.'home';
91+
putenv('COMPOSER_HOME='.$_SERVER['COMPOSER_HOME']);
9092

9193
$cmd = 'php '.escapeshellarg(self::$pharPath).' --no-ansi '.$testData['RUN'];
9294
$proc = new Process($cmd, __DIR__.'/Fixtures/functional', null, null, 300);

0 commit comments

Comments
 (0)