diff --git a/doc/01-basic-usage.md b/doc/01-basic-usage.md index 06d2a8c5d..abf684488 100644 --- a/doc/01-basic-usage.md +++ b/doc/01-basic-usage.md @@ -75,7 +75,7 @@ Version constraints can be specified in a few different ways. Name | Example | Description -------------- | ------------------------------------------------------------------ | ----------- Exact version | `1.0.2` | You can specify the exact version of a package. -Range | `>=1.0` `>=1.0,<2.0` >=1.0,<1.1 | >=1.2 | By using comparison operators you can specify ranges of valid versions. Valid operators are `>`, `>=`, `<`, `<=`, `!=`.
You can define multiple ranges. Ranges separated by a comma (`,`) will be treated as a **logical AND**. A pipe (|) will be treated as a **logical OR**. AND has higher precedence than OR. +Range | `>=1.0` `>=1.0,<2.0` >=1.0,<1.1 | >=1.2 | By using comparison operators you can specify ranges of valid versions. Valid operators are `>`, `>=`, `<`, `<=`, `!=`.
You can define multiple ranges. Ranges separated by a space (` `) or comma (`,`) will be treated as a **logical AND**. A pipe (|) will be treated as a **logical OR**. AND has higher precedence than OR. Wildcard | `1.0.*` | You can specify a pattern with a `*` wildcard. `1.0.*` is the equivalent of `>=1.0,<1.1`. Tilde Operator | `~1.2` | Very useful for projects that follow semantic versioning. `~1.2` is equivalent to `>=1.2,<2.0`. For more details, read the next section below. diff --git a/doc/04-schema.md b/doc/04-schema.md index c768edb72..9799b4a5c 100644 --- a/doc/04-schema.md +++ b/doc/04-schema.md @@ -345,10 +345,10 @@ dependencies from being installed. Lists packages that conflict with this version of this package. They will not be allowed to be installed together with your package. -Note that when specifying ranges like `<1.0, >= 1.1` in a `conflict` link, +Note that when specifying ranges like `<1.0 >=1.1` in a `conflict` link, this will state a conflict with all versions that are less than 1.0 *and* equal or newer than 1.1 at the same time, which is probably not what you want. You -probably want to go for `<1.0 | >= 1.1` in this case. +probably want to go for `<1.0 | >=1.1` in this case. #### replace diff --git a/src/Composer/Package/Version/VersionParser.php b/src/Composer/Package/Version/VersionParser.php index a141bdc43..a2ad3bd11 100644 --- a/src/Composer/Package/Version/VersionParser.php +++ b/src/Composer/Package/Version/VersionParser.php @@ -233,7 +233,7 @@ class VersionParser $orConstraints = preg_split('{\s*\|\s*}', trim($constraints)); $orGroups = array(); foreach ($orConstraints as $constraints) { - $andConstraints = preg_split('{\s*,\s*}', $constraints); + $andConstraints = preg_split('{(?<])\s*[, ]+\s*(?!as)}', $constraints); if (count($andConstraints) > 1) { $constraintObjects = array(); diff --git a/tests/Composer/Test/Package/Version/VersionParserTest.php b/tests/Composer/Test/Package/Version/VersionParserTest.php index c8136f6f3..5a15dd714 100644 --- a/tests/Composer/Test/Package/Version/VersionParserTest.php +++ b/tests/Composer/Test/Package/Version/VersionParserTest.php @@ -221,6 +221,8 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase 'completes version' => array('=1.0', new VersionConstraint('=', '1.0.0.0')), 'shorthand beta' => array('1.2.3b5', new VersionConstraint('=', '1.2.3.0-beta5')), 'accepts spaces' => array('>= 1.2.3', new VersionConstraint('>=', '1.2.3.0')), + 'accepts spaces/2' => array('< 1.2.3', new VersionConstraint('<', '1.2.3.0-dev')), + 'accepts spaces/3' => array('> 1.2.3', new VersionConstraint('>', '1.2.3.0')), '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')), @@ -291,13 +293,27 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase ); } - public function testParseConstraintsMulti() + /** + * @dataProvider multiConstraintProvider + */ + public function testParseConstraintsMulti($constraint) { $parser = new VersionParser; $first = new VersionConstraint('>', '2.0.0.0'); $second = new VersionConstraint('<=', '3.0.0.0'); $multi = new MultiConstraint(array($first, $second)); - $this->assertSame((string) $multi, (string) $parser->parseConstraints('>2.0,<=3.0')); + $this->assertSame((string) $multi, (string) $parser->parseConstraints($constraint)); + } + + public function multiConstraintProvider() + { + return array( + array('>2.0,<=3.0'), + array('>2.0 <=3.0'), + array('>2.0, <=3.0'), + array('>2.0 ,<=3.0'), + array('>2.0 , <=3.0'), + ); } public function testParseConstraintsMultiWithStabilitySuffix()