Fix env var handling when variables_order includes E and symfony/console 3.3.15+ is used, fixes #9930

main
Jordi Boggiano 3 years ago
parent e0366bc760
commit 91dd175f74
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC

@ -10,6 +10,7 @@ require __DIR__.'/../src/bootstrap.php';
use Composer\Console\Application; use Composer\Console\Application;
use Composer\XdebugHandler\XdebugHandler; use Composer\XdebugHandler\XdebugHandler;
use Composer\Util\Platform;
error_reporting(-1); error_reporting(-1);
@ -57,8 +58,7 @@ if (function_exists('ini_set')) {
unset($memoryLimit); unset($memoryLimit);
} }
$_SERVER['COMPOSER_BINARY'] = realpath($_SERVER['argv'][0]); Platform::setEnv('COMPOSER_BINARY', realpath($_SERVER['argv'][0]));
putenv('COMPOSER_BINARY='.$_SERVER['COMPOSER_BINARY']);
// run the command application // run the command application
$application = new Application(); $application = new Application();

@ -24,6 +24,7 @@ use Composer\Repository\PlatformRepository;
use Composer\Semver\Constraint\Bound; use Composer\Semver\Constraint\Bound;
use Composer\Semver\Constraint\MatchAllConstraint; use Composer\Semver\Constraint\MatchAllConstraint;
use Composer\Util\Filesystem; use Composer\Util\Filesystem;
use Composer\Util\Platform;
use Composer\Script\ScriptEvents; use Composer\Script\ScriptEvents;
use Composer\Util\PackageSorter; use Composer\Util\PackageSorter;
use Composer\Json\JsonFile; use Composer\Json\JsonFile;
@ -158,8 +159,7 @@ class AutoloadGenerator
// set COMPOSER_DEV_MODE in case not set yet so it is available in the dump-autoload autoload // set COMPOSER_DEV_MODE in case not set yet so it is available in the dump-autoload autoload
if (!isset($_SERVER['COMPOSER_DEV_MODE'])) { if (!isset($_SERVER['COMPOSER_DEV_MODE'])) {
$_SERVER['COMPOSER_DEV_MODE'] = $this->devMode ? '1' : '0'; Platform::putEnv('COMPOSER_DEV_MODE', $this->devMode ? '1' : '0');
putenv('COMPOSER_DEV_MODE='.$_SERVER['COMPOSER_DEV_MODE']);
} }
$this->eventDispatcher->dispatchScript(ScriptEvents::PRE_AUTOLOAD_DUMP, $this->devMode, array(), array( $this->eventDispatcher->dispatchScript(ScriptEvents::PRE_AUTOLOAD_DUMP, $this->devMode, array(), array(

@ -37,6 +37,7 @@ use Symfony\Component\Finder\Finder;
use Composer\Json\JsonFile; use Composer\Json\JsonFile;
use Composer\Config\JsonConfigSource; use Composer\Config\JsonConfigSource;
use Composer\Util\Filesystem; use Composer\Util\Filesystem;
use Composer\Util\Platform;
use Composer\Util\ProcessExecutor; use Composer\Util\ProcessExecutor;
use Composer\Package\Version\VersionParser; use Composer\Package\Version\VersionParser;
@ -453,8 +454,7 @@ EOT
$io->writeError('<info>Created project in ' . $directory . '</info>'); $io->writeError('<info>Created project in ' . $directory . '</info>');
chdir($directory); chdir($directory);
$_SERVER['COMPOSER_ROOT_VERSION'] = $package->getPrettyVersion(); Platform::putEnv('COMPOSER_ROOT_VERSION', $package->getPrettyVersion());
putenv('COMPOSER_ROOT_VERSION='.$_SERVER['COMPOSER_ROOT_VERSION']);
return $installedFromVcs; return $installedFromVcs;
} }

@ -14,6 +14,7 @@ namespace Composer\Command;
use Composer\Factory; use Composer\Factory;
use Composer\Util\Filesystem; use Composer\Util\Filesystem;
use Composer\Util\Platform;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\StringInput; use Symfony\Component\Console\Input\StringInput;
@ -81,8 +82,7 @@ EOT
// The COMPOSER env var should not apply to the global execution scope // The COMPOSER env var should not apply to the global execution scope
if (getenv('COMPOSER')) { if (getenv('COMPOSER')) {
putenv('COMPOSER'); Platform::clearEnv('COMPOSER');
unset($_SERVER['COMPOSER']);
} }
// change to global dir // change to global dir

@ -15,6 +15,7 @@ namespace Composer\Command;
use Composer\Script\Event as ScriptEvent; use Composer\Script\Event as ScriptEvent;
use Composer\Script\ScriptEvents; use Composer\Script\ScriptEvents;
use Composer\Util\ProcessExecutor; use Composer\Util\ProcessExecutor;
use Composer\Util\Platform;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
@ -103,8 +104,7 @@ EOT
ProcessExecutor::setTimeout((int) $timeout); ProcessExecutor::setTimeout((int) $timeout);
} }
$_SERVER['COMPOSER_DEV_MODE'] = $devMode ? '1' : '0'; Platform::putEnv('COMPOSER_DEV_MODE', $devMode ? '1' : '0');
putenv('COMPOSER_DEV_MODE='.$_SERVER['COMPOSER_DEV_MODE']);
return $composer->getEventDispatcher()->dispatchScript($script, $devMode, $args); return $composer->getEventDispatcher()->dispatchScript($script, $devMode, $args);
} }

@ -143,8 +143,7 @@ class Application extends BaseApplication
if ($input->hasParameterOption('--no-cache')) { if ($input->hasParameterOption('--no-cache')) {
$io->writeError('Disabling cache usage', true, IOInterface::DEBUG); $io->writeError('Disabling cache usage', true, IOInterface::DEBUG);
$_SERVER['COMPOSER_CACHE_DIR'] = Platform::isWindows() ? 'nul' : '/dev/null'; Platform::putEnv('COMPOSER_CACHE_DIR', Platform::isWindows() ? 'nul' : '/dev/null');
putenv('COMPOSER_CACHE_DIR='.$_SERVER['COMPOSER_CACHE_DIR']);
} }
// switch working dir // switch working dir

@ -247,9 +247,12 @@ class EventDispatcher
} }
if (strpos($exec, '@putenv ') === 0) { if (strpos($exec, '@putenv ') === 0) {
putenv(substr($exec, 8)); if (false === strpos($exec, '=')) {
list($var, $value) = explode('=', substr($exec, 8), 2); Platform::clearEnv(substr($exec, 8));
$_SERVER[$var] = $value; } else {
list($var, $value) = explode('=', substr($exec, 8), 2);
Platform::putEnv($var, $value);
}
continue; continue;
} }
@ -274,8 +277,7 @@ class EventDispatcher
$finder = new PhpExecutableFinder(); $finder = new PhpExecutableFinder();
$phpPath = $finder->find(false); $phpPath = $finder->find(false);
if ($phpPath) { if ($phpPath) {
$_SERVER['PHP_BINARY'] = $phpPath; Platform::putEnv('PHP_BINARY', $phpPath);
putenv('PHP_BINARY=' . $_SERVER['PHP_BINARY']);
} }
if (Platform::isWindows()) { if (Platform::isWindows()) {
@ -539,8 +541,7 @@ class EventDispatcher
if (is_dir($binDir)) { if (is_dir($binDir)) {
$binDir = realpath($binDir); $binDir = realpath($binDir);
if (isset($_SERVER[$pathStr]) && !preg_match('{(^|'.PATH_SEPARATOR.')'.preg_quote($binDir).'($|'.PATH_SEPARATOR.')}', $_SERVER[$pathStr])) { if (isset($_SERVER[$pathStr]) && !preg_match('{(^|'.PATH_SEPARATOR.')'.preg_quote($binDir).'($|'.PATH_SEPARATOR.')}', $_SERVER[$pathStr])) {
$_SERVER[$pathStr] = $binDir.PATH_SEPARATOR.getenv($pathStr); Platform::putEnv($pathStr, $binDir.PATH_SEPARATOR.getenv($pathStr));
putenv($pathStr.'='.$_SERVER[$pathStr]);
} }
} }
} }

@ -56,6 +56,7 @@ use Composer\Repository\RepositoryInterface;
use Composer\Repository\RepositoryManager; use Composer\Repository\RepositoryManager;
use Composer\Repository\LockArrayRepository; use Composer\Repository\LockArrayRepository;
use Composer\Script\ScriptEvents; use Composer\Script\ScriptEvents;
use Composer\Util\Platform;
/** /**
* @author Jordi Boggiano <j.boggiano@seld.be> * @author Jordi Boggiano <j.boggiano@seld.be>
@ -224,8 +225,7 @@ class Installer
} }
if ($this->runScripts) { if ($this->runScripts) {
$_SERVER['COMPOSER_DEV_MODE'] = $this->devMode ? '1' : '0'; Platform::putEnv('COMPOSER_DEV_MODE', $this->devMode ? '1' : '0');
putenv('COMPOSER_DEV_MODE='.$_SERVER['COMPOSER_DEV_MODE']);
// dispatch pre event // dispatch pre event
// should we treat this more strictly as running an update and then running an install, triggering events multiple times? // should we treat this more strictly as running an update and then running an install, triggering events multiple times?

@ -353,29 +353,24 @@ class Git
// added in git 1.7.1, prevents prompting the user for username/password // added in git 1.7.1, prevents prompting the user for username/password
if (getenv('GIT_ASKPASS') !== 'echo') { if (getenv('GIT_ASKPASS') !== 'echo') {
putenv('GIT_ASKPASS=echo'); Platform::putEnv('GIT_ASKPASS', 'echo');
$_SERVER['GIT_ASKPASS'] = 'echo';
} }
// clean up rogue git env vars in case this is running in a git hook // clean up rogue git env vars in case this is running in a git hook
if (getenv('GIT_DIR')) { if (getenv('GIT_DIR')) {
putenv('GIT_DIR'); Platform::clearEnv('GIT_DIR');
unset($_SERVER['GIT_DIR']);
} }
if (getenv('GIT_WORK_TREE')) { if (getenv('GIT_WORK_TREE')) {
putenv('GIT_WORK_TREE'); Platform::clearEnv('GIT_WORK_TREE');
unset($_SERVER['GIT_WORK_TREE']);
} }
// Run processes with predictable LANGUAGE // Run processes with predictable LANGUAGE
if (getenv('LANGUAGE') !== 'C') { if (getenv('LANGUAGE') !== 'C') {
putenv('LANGUAGE=C'); Platform::putEnv('LANGUAGE', 'C');
$_SERVER['LANGUAGE'] = 'C';
} }
// clean up env for OSX, see https://github.com/composer/composer/issues/2146#issuecomment-35478940 // clean up env for OSX, see https://github.com/composer/composer/issues/2146#issuecomment-35478940
putenv("DYLD_LIBRARY_PATH"); Platform::clearEnv('DYLD_LIBRARY_PATH');
unset($_SERVER['DYLD_LIBRARY_PATH']);
} }
public static function getGitHubDomainsRegex(Config $config) public static function getGitHubDomainsRegex(Config $config)

@ -24,6 +24,33 @@ class Platform
/** @var ?bool */ /** @var ?bool */
private static $isWindowsSubsystemForLinux = null; private static $isWindowsSubsystemForLinux = null;
/**
* putenv() equivalent but updates the runtime global variables too
*
* @param string $name
* @param string $value
* @return void
*/
public function putEnv($name, $value)
{
$value = (string) $value;
putenv($name . '=' . $value);
$_SERVER[$name] = $_ENV[$name] = $value;
}
/**
* putenv('X') equivalent but updates the runtime global variables too
*
* @param string $name
* @param string $value
* @return void
*/
public function clearEnv($name)
{
putenv($name);
unset($_SERVER[$name], $_ENV[$name]);
}
/** /**
* Parses tildes and environment variables in paths. * Parses tildes and environment variables in paths.
* *

@ -85,8 +85,7 @@ class Svn
public static function cleanEnv() public static function cleanEnv()
{ {
// clean up env for OSX, see https://github.com/composer/composer/issues/2146#issuecomment-35478940 // clean up env for OSX, see https://github.com/composer/composer/issues/2146#issuecomment-35478940
putenv("DYLD_LIBRARY_PATH"); Platform::clearEnv('DYLD_LIBRARY_PATH');
unset($_SERVER['DYLD_LIBRARY_PATH']);
} }
/** /**

@ -18,6 +18,13 @@ use Symfony\Component\Console\Output\OutputInterface;
class ApplicationTest extends TestCase class ApplicationTest extends TestCase
{ {
public function tearDown()
{
parent::tearDown();
putenv('COMPOSER_NO_INTERACTION');
}
public function testDevWarning() public function testDevWarning()
{ {
$application = new Application; $application = new Application;

Loading…
Cancel
Save