From c10eb66ac4afc8ee6d2bd7a1154c05214e182136 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 16 May 2012 17:14:56 +0200 Subject: [PATCH] Ignore references when parsing dev versions --- src/Composer/Package/Version/VersionParser.php | 6 ++++++ .../Test/Package/Version/VersionParserTest.php | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/Composer/Package/Version/VersionParser.php b/src/Composer/Package/Version/VersionParser.php index eedd5f3ae..9aefbb805 100644 --- a/src/Composer/Package/Version/VersionParser.php +++ b/src/Composer/Package/Version/VersionParser.php @@ -33,6 +33,8 @@ class VersionParser */ static public function parseStability($version) { + $version = preg_replace('{#[a-f0-9]+$}i', '', $version); + if ('dev-' === substr($version, 0, 4) || '-dev' === substr($version, -4)) { return 'dev'; } @@ -155,6 +157,10 @@ class VersionParser $constraints = empty($match[1]) ? '*' : $match[1]; } + if (preg_match('{^(dev-[^,\s@]+?|[^,\s@]+?\.x-dev)#[a-f0-9]+$}i', $constraints, $match)) { + $constraints = $match[1]; + } + $constraints = preg_split('{\s*,\s*}', trim($constraints)); if (count($constraints) > 1) { diff --git a/tests/Composer/Test/Package/Version/VersionParserTest.php b/tests/Composer/Test/Package/Version/VersionParserTest.php index 0be1b7269..8c453f56c 100644 --- a/tests/Composer/Test/Package/Version/VersionParserTest.php +++ b/tests/Composer/Test/Package/Version/VersionParserTest.php @@ -112,6 +112,21 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase $this->assertSame((string) new VersionConstraint('=', '1.0.0.0'), (string) $parser->parseConstraints('1.0@dev')); } + public function testParseConstraintsIgnoresReferenceOnDevVersion() + { + $parser = new VersionParser; + $this->assertSame((string) new VersionConstraint('=', '1.0.9999999.9999999-dev'), (string) $parser->parseConstraints('1.0.x-dev#abcd123')); + } + + /** + * @expectedException UnexpectedValueException + */ + public function testParseConstraintsFailsOnBadReference() + { + $parser = new VersionParser; + $this->assertSame((string) new VersionConstraint('=', '1.0.0.0'), (string) $parser->parseConstraints('1.0#abcd123')); + } + /** * @dataProvider simpleConstraints */ @@ -213,6 +228,7 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase return array( array('stable', '1.0'), array('dev', 'v2.0.x-dev'), + array('dev', 'v2.0.x-dev#abc123'), array('RC', '3.0-RC2'), array('dev', 'dev-master'), array('dev', '3.1.2-dev'),