浏览代码

Fix regex escaping and remove constants

Jordi Boggiano 9 年之前
父节点
当前提交
3c640e689e
共有 2 个文件被更改,包括 6 次插入10 次删除
  1. 0 4
      src/Composer/Config.php
  2. 6 6
      src/Composer/Downloader/DownloadManager.php

+ 0 - 4
src/Composer/Config.php

@@ -21,10 +21,6 @@ class Config
 {
     const RELATIVE_PATHS = 1;
 
-    const INSTALL_PREFERENCE_AUTO = 'auto';
-    const INSTALL_PREFERENCE_DIST = 'dist';
-    const INSTALL_PREFERENCE_SOURCE = 'source';
-    
     public static $defaultConfig = array(
         'process-timeout' => 300,
         'use-include-path' => false,

+ 6 - 6
src/Composer/Downloader/DownloadManager.php

@@ -197,7 +197,7 @@ class DownloadManager
             throw new \InvalidArgumentException('Package '.$package.' must have a source or dist specified');
         }
 
-        if (!$preferSource && ($this->preferDist || Config::INSTALL_PREFERENCE_DIST === $this->resolvePackageInstallPreference($package))) {
+        if (!$preferSource && ($this->preferDist || 'dist' === $this->resolvePackageInstallPreference($package))) {
             $sources = array_reverse($sources);
         }
 
@@ -308,15 +308,15 @@ class DownloadManager
     protected function resolvePackageInstallPreference(PackageInterface $package)
     {
         foreach ($this->packagePreferences as $pattern => $preference) {
-            $pattern = '{^'.str_replace('*', '.*', $pattern).'$}i';
+            $pattern = '{^'.str_replace('\\*', '.*', preg_quote($pattern)).'$}i';
             if (preg_match($pattern, $package->getName())) {
-                if (Config::INSTALL_PREFERENCE_DIST === $preference || (!$package->isDev() && Config::INSTALL_PREFERENCE_AUTO === $preference)) {
-                    return Config::INSTALL_PREFERENCE_DIST;
+                if ('dist' === $preference || (!$package->isDev() && 'auto' === $preference)) {
+                    return 'dist';
                 }
-                return Config::INSTALL_PREFERENCE_SOURCE;
+                return 'source';
             }
         }
 
-        return $package->isDev() ? Config::INSTALL_PREFERENCE_SOURCE : Config::INSTALL_PREFERENCE_DIST;
+        return $package->isDev() ? 'source' : 'dist';
     }
 }