From f604ca5762c9eed93e001b54d6682da00921fa95 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 8 Apr 2012 17:02:29 +0200 Subject: [PATCH] Allow .x in version constraints as alias for .* --- src/Composer/Package/Version/VersionParser.php | 7 ++++--- tests/Composer/Test/Package/Version/VersionParserTest.php | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Composer/Package/Version/VersionParser.php b/src/Composer/Package/Version/VersionParser.php index 763929613..6791fd5f8 100644 --- a/src/Composer/Package/Version/VersionParser.php +++ b/src/Composer/Package/Version/VersionParser.php @@ -149,12 +149,13 @@ class VersionParser private function parseConstraint($constraint) { - if ('*' === $constraint || '*.*' === $constraint || '*.*.*' === $constraint || '*.*.*.*' === $constraint) { + $normalized = strtr($constraint, 'x', '*'); + if ('*' === $normalized || '*.*' === $normalized || '*.*.*' === $normalized || '*.*.*.*' === $normalized) { return array(); } // match wildcard constraints - if (preg_match('{^(\d+)(?:\.(\d+))?(?:\.(\d+))?\.\*$}', $constraint, $matches)) { + if (preg_match('{^(\d+)(?:\.(\d+))?(?:\.(\d+))?\.\*$}', $normalized, $matches)) { if (isset($matches[3])) { $highVersion = $matches[1] . '.' . $matches[2] . '.' . $matches[3] . '.9999999'; if ($matches[3] === '0') { @@ -185,7 +186,7 @@ class VersionParser } // match operators constraints - if (preg_match('{^(>=?|<=?|==?)?\s*(.*)}', $constraint, $matches)) { + if (preg_match('{^(>=?|<=?|==?)?\s*(.*)}', $normalized, $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 c33bb2860..956747e2d 100644 --- a/tests/Composer/Test/Package/Version/VersionParserTest.php +++ b/tests/Composer/Test/Package/Version/VersionParserTest.php @@ -154,8 +154,8 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase array('2.*', new VersionConstraint('>', '1.9999999.9999999.9999999'), new VersionConstraint('<', '2.9999999.9999999.9999999')), array('20.*', new VersionConstraint('>', '19.9999999.9999999.9999999'), new VersionConstraint('<', '20.9999999.9999999.9999999')), array('2.0.*', new VersionConstraint('>', '1.9999999.9999999.9999999'), new VersionConstraint('<', '2.0.9999999.9999999')), - array('2.2.*', new VersionConstraint('>', '2.1.9999999.9999999'), new VersionConstraint('<', '2.2.9999999.9999999')), - array('2.10.*', new VersionConstraint('>', '2.9.9999999.9999999'), new VersionConstraint('<', '2.10.9999999.9999999')), + array('2.2.x', new VersionConstraint('>', '2.1.9999999.9999999'), new VersionConstraint('<', '2.2.9999999.9999999')), + array('2.10.x', new VersionConstraint('>', '2.9.9999999.9999999'), new VersionConstraint('<', '2.10.9999999.9999999')), array('2.1.3.*', new VersionConstraint('>', '2.1.2.9999999'), new VersionConstraint('<', '2.1.3.9999999')), array('0.*', null, new VersionConstraint('<', '0.9999999.9999999.9999999')), );