From e09f6900da44697e0b2afd296a66105014549da7 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 11 Oct 2011 11:49:32 +0200 Subject: [PATCH] Fix up version parsing --- src/Composer/Package/Version/VersionParser.php | 17 ++++++++++++----- .../Test/Package/Version/VersionParserTest.php | 3 +++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Composer/Package/Version/VersionParser.php b/src/Composer/Package/Version/VersionParser.php index 59d6f5382..725ee7d7f 100644 --- a/src/Composer/Package/Version/VersionParser.php +++ b/src/Composer/Package/Version/VersionParser.php @@ -34,7 +34,7 @@ class VersionParser { $version = trim($version); - if (in_array($version, array('master', 'trunk'))) { + if (preg_match('{^(?:master|trunk)(?:[.-]?dev)?$}i', $version)) { return '9999999-dev'; } @@ -66,6 +66,12 @@ class VersionParser return $version; } + if (preg_match('{(.*?)[.-]?dev$}i', $version, $match)) { + try { + return $this->normalizeBranch($match[1]); + } catch (\Exception $e) {} + } + throw new \UnexpectedValueException('Invalid version string '.$version); } @@ -146,10 +152,11 @@ class VersionParser } // match operators constraints - if (preg_match('{^(>=?|<=?|==?)?\s*(\d+.*)}', $constraint, $matches)) { - $version = $this->normalize($matches[2]); - - return array(new VersionConstraint($matches[1] ?: '=', $version)); + if (preg_match('{^(>=?|<=?|==?)?\s*(.*)}', $constraint, $matches)) { + try { + $version = $this->normalize($matches[2]); + return array(new VersionConstraint($matches[1] ?: '=', $version)); + } catch (\Exception $e) {} } throw new \UnexpectedValueException('Could not parse version constraint '.$constraint); diff --git a/tests/Composer/Test/Package/Version/VersionParserTest.php b/tests/Composer/Test/Package/Version/VersionParserTest.php index 4a6909e23..e6d731dc9 100644 --- a/tests/Composer/Test/Package/Version/VersionParserTest.php +++ b/tests/Composer/Test/Package/Version/VersionParserTest.php @@ -51,6 +51,7 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase 'parses dt+patch' => array('20100102-203040-p1', '20100102-203040-patch1'), 'parses master' => array('master', '9999999-dev'), 'parses trunk' => array('trunk', '9999999-dev'), + 'parses trunk/2' => array('trunk-dev', '9999999-dev'), ); } @@ -119,6 +120,8 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase 'no op means eq' => array('1.2.3', new VersionConstraint('=', '1.2.3.0')), 'completes version' => array('=1.0', new VersionConstraint('=', '1.0.0.0')), 'accepts spaces' => array('>= 1.2.3', new VersionConstraint('>=', '1.2.3.0')), + 'accepts master' => array('>=master-dev', new VersionConstraint('>=', '9999999-dev')), + 'accepts master/2' => array('master-dev', new VersionConstraint('=', '9999999-dev')), ); }