Explorar o código

Fix handling of COMPOSER_DISCARD_CHANGES env var

Jordi Boggiano %!s(int64=12) %!d(string=hai) anos
pai
achega
1d5e3c5a0d
Modificáronse 1 ficheiros con 16 adicións e 2 borrados
  1. 16 2
      src/Composer/Config.php

+ 16 - 2
src/Composer/Config.php

@@ -177,9 +177,23 @@ class Config
                 return rtrim($this->process($this->config[$key]), '/\\');
                 return rtrim($this->process($this->config[$key]), '/\\');
 
 
             case 'discard-changes':
             case 'discard-changes':
-                if (!in_array(getenv('COMPOSER_DISCARD_CHANGES') ?: $this->config[$key], array(true, false, 'stash'), true)) {
+                if ($env = getenv('COMPOSER_DISCARD_CHANGES')) {
+                    if (!in_array($env, array('stash', 'true', 'false', '1', '0'), true)) {
+                        throw new \RuntimeException(
+                            "Invalid value for 'discard-changes': {$this->config[$key]}, expected 1, 0, true, false or stash"
+                        );
+                    }
+                    if ('stash' === $env) {
+                        return 'stash';
+                    }
+
+                    // convert string value to bool
+                    return $env !== 'false' && (bool) $env;
+                }
+
+                if (!in_array($this->config[$key], array(true, false, 'stash'), true)) {
                     throw new \RuntimeException(
                     throw new \RuntimeException(
-                        "Invalid value for 'discard-changes': {$this->config[$key]}"
+                        "Invalid value for 'discard-changes': {$this->config[$key]}, expected true, false or stash"
                     );
                     );
                 }
                 }