Detect ~> misuse and suggest fix, fixes #2476

main
Jordi Boggiano 11 years ago
parent 45c8d5c817
commit 80499bb024

@ -275,7 +275,14 @@ class VersionParser
// version, to ensure that unstable instances of the current version are allowed.
// however, if a stability suffix is added to the constraint, then a >= match on the current version is
// used instead
if (preg_match('{^~(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:\.(\d+))?'.self::$modifierRegex.'?$}i', $constraint, $matches)) {
if (preg_match('{^~>?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:\.(\d+))?'.self::$modifierRegex.'?$}i', $constraint, $matches)) {
if (substr($constraint, 0, 2) === '~>') {
throw new \UnexpectedValueException(
'Could not parse version constraint '.$constraint.': '.
'Invalid operator "~>", you probably meant to use the "~" operator'
);
}
// Work out which position in the version we are operating at
if (isset($matches[4]) && '' !== $matches[4]) {
$position = 4;

@ -181,6 +181,16 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase
$this->assertSame((string) new VersionConstraint('=', '1.0.0.0'), (string) $parser->parseConstraints('1.0#trunk/@123'));
}
/**
* @expectedException UnexpectedValueException
* @expectedExceptionMessage Invalid operator "~>", you probably meant to use the "~" operator
*/
public function testParseConstraintsNudgesRubyDevsTowardsThePathOfRighteousness()
{
$parser = new VersionParser;
$parser->parseConstraints('~>1.2');
}
/**
* @dataProvider simpleConstraints
*/

Loading…
Cancel
Save