1
0
Fork 0

Add more tests and validate that there is only one comma

pull/2596/head
Jordi Boggiano 2014-01-15 17:13:42 +01:00
parent ca168d478b
commit 4c713978e9
2 changed files with 8 additions and 1 deletions

View File

@ -233,7 +233,7 @@ class VersionParser
$orConstraints = preg_split('{\s*\|\s*}', trim($constraints)); $orConstraints = preg_split('{\s*\|\s*}', trim($constraints));
$orGroups = array(); $orGroups = array();
foreach ($orConstraints as $constraints) { foreach ($orConstraints as $constraints) {
$andConstraints = preg_split('{(?<!as|[=><])\s*[, ]+\s*(?!as)}', $constraints); $andConstraints = preg_split('{(?<!^|as|[=>< ,]) *[, ] *(?!,|as|$)}', $constraints);
if (count($andConstraints) > 1) { if (count($andConstraints) > 1) {
$constraintObjects = array(); $constraintObjects = array();

View File

@ -313,6 +313,10 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase
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'), 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 '),
); );
} }
@ -365,6 +369,9 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase
return array( return array(
'empty ' => array(''), 'empty ' => array(''),
'invalid version' => array('1.0.0-meh'), 'invalid version' => array('1.0.0-meh'),
'operator abuse' => array('>2.0,,<=3.0'),
'operator abuse/2' => array('>2.0 ,, <=3.0'),
'operator abuse/3' => array('>2.0 || <=3.0'),
); );
} }