From 8654c43c62b4f5d514656e67096ce7a5c61ce467 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 9 Apr 2012 16:00:02 +0200 Subject: [PATCH] Fix version parser regression, fixes #550 --- src/Composer/Package/Version/VersionParser.php | 7 +++---- tests/Composer/Test/Package/Version/VersionParserTest.php | 5 +++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Composer/Package/Version/VersionParser.php b/src/Composer/Package/Version/VersionParser.php index 6791fd5f8..0329514d5 100644 --- a/src/Composer/Package/Version/VersionParser.php +++ b/src/Composer/Package/Version/VersionParser.php @@ -149,13 +149,12 @@ class VersionParser private function parseConstraint($constraint) { - $normalized = strtr($constraint, 'x', '*'); - if ('*' === $normalized || '*.*' === $normalized || '*.*.*' === $normalized || '*.*.*.*' === $normalized) { + if (preg_match('{^[x*](\.[x*])*$}i', $constraint)) { return array(); } // match wildcard constraints - if (preg_match('{^(\d+)(?:\.(\d+))?(?:\.(\d+))?\.\*$}', $normalized, $matches)) { + if (preg_match('{^(\d+)(?:\.(\d+))?(?:\.(\d+))?\.[x*]$}', $constraint, $matches)) { if (isset($matches[3])) { $highVersion = $matches[1] . '.' . $matches[2] . '.' . $matches[3] . '.9999999'; if ($matches[3] === '0') { @@ -186,7 +185,7 @@ class VersionParser } // match operators constraints - if (preg_match('{^(>=?|<=?|==?)?\s*(.*)}', $normalized, $matches)) { + if (preg_match('{^(>=?|<=?|==?)?\s*(.*)}', $constraint, $matches)) { try { $version = $this->normalize($matches[2]); return array(new VersionConstraint($matches[1] ?: '=', $version)); diff --git a/tests/Composer/Test/Package/Version/VersionParserTest.php b/tests/Composer/Test/Package/Version/VersionParserTest.php index 956747e2d..26cceced6 100644 --- a/tests/Composer/Test/Package/Version/VersionParserTest.php +++ b/tests/Composer/Test/Package/Version/VersionParserTest.php @@ -117,6 +117,10 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase public function simpleConstraints() { return array( + 'match any' => array('*', new MultiConstraint(array())), + 'match any/2' => array('*.*', new MultiConstraint(array())), + 'match any/3' => array('*.x.*', new MultiConstraint(array())), + 'match any/4' => array('x.x.x.*', new MultiConstraint(array())), 'greater than' => array('>1.0.0', new VersionConstraint('>', '1.0.0.0')), 'lesser than' => array('<1.2.3.4', new VersionConstraint('<', '1.2.3.4')), 'less/eq than' => array('<=1.2.3', new VersionConstraint('<=', '1.2.3.0')), @@ -129,6 +133,7 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase 'accepts master' => array('>=dev-master', new VersionConstraint('>=', '9999999-dev')), 'accepts master/2' => array('dev-master', new VersionConstraint('=', '9999999-dev')), 'accepts arbitrary' => array('dev-feature-a', new VersionConstraint('=', 'dev-feature-a')), + 'regression #550' => array('dev-some-fix', new VersionConstraint('=', 'dev-some-fix')), 'ignores aliases' => array('dev-master as 1.0.0', new VersionConstraint('=', '1.0.0.0')), ); }