1
0
Fork 0

Detect ~> misuse and suggest fix, fixes #2476

pull/2488/head
Jordi Boggiano 2013-12-06 11:57:37 +01:00
parent 45c8d5c817
commit 80499bb024
2 changed files with 18 additions and 1 deletions

View File

@ -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;

View File

@ -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
*/