Преглед изворни кода

Update version parser to support any branch name

Jordi Boggiano пре 13 година
родитељ
комит
3e6176eccf
1 измењених фајлова са 8 додато и 3 уклоњено
  1. 8 3
      src/Composer/Package/Version/VersionParser.php

+ 8 - 3
src/Composer/Package/Version/VersionParser.php

@@ -34,10 +34,15 @@ class VersionParser
     {
         $version = trim($version);
 
-        if (preg_match('{^(?:master|trunk|default)(?:[.-]?dev)?$}i', $version)) {
+        // match master-like branches
+        if (preg_match('{^(?:dev-)?(?:master|trunk|default)$}i', $version)) {
             return '9999999-dev';
         }
 
+        if ('dev-' === strtolower(substr($version, 0, 4))) {
+            return strtolower($version);
+        }
+
         // match classical versioning
         if (preg_match('{^v?(\d{1,3})(\.\d+)?(\.\d+)?(\.\d+)?'.$this->modifierRegex.'$}i', $version, $matches)) {
             $version = $matches[1]
@@ -53,7 +58,7 @@ class VersionParser
         // add version modifiers if a version was matched
         if (isset($index)) {
             if (!empty($matches[$index])) {
-                $mod = array('{^pl?$}', '{^rc$}');
+                $mod = array('{^pl?$}i', '{^rc$}i');
                 $modNormalized = array('patch', 'RC');
                 $version .= '-'.preg_replace($mod, $modNormalized, strtolower($matches[$index]))
                     . (!empty($matches[$index+1]) ? $matches[$index+1] : '');
@@ -97,7 +102,7 @@ class VersionParser
             return str_replace('x', '9999999', $version).'-dev';
         }
 
-        throw new \UnexpectedValueException('Invalid branch name '.$name);
+        return 'dev-'.$name;
     }
 
     /**