Skip to content

Commit

Permalink
Fix the invalid operator ~>
Browse files Browse the repository at this point in the history
  • Loading branch information
francoispluchino committed Apr 9, 2017
1 parent 5409f9c commit 0bfdd30
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Converter/SemverConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ protected function matchRangeTokenStep2($i, $match, array &$matches, &$special,
{
if (in_array($match, array('', '<', '>', '=', ','))) {
$replace = in_array($match, array('<', '>')) ? $match : $replace;
$matches[$i] = '~' === $special && in_array($replace, array('<', '>')) ? '' : $matches[$i];
} elseif ('~' === $match) {
$special = $match;
} elseif (in_array($match, array('EQUAL', '^'))) {
Expand Down Expand Up @@ -181,7 +182,7 @@ protected function matchRangeTokenStep4($i, $match, array &$matches, &$special,
$match .= (false === strpos($match, '.') ? '.x' : '');
$version = explode('.', $match);
$change = count($version) - 2;
$version[$change] = intval($version[$change]) + 1;
$version[$change] = (int) ($version[$change]) + 1;
$match = str_replace(array('*', 'x', 'X'), '0', implode('.', $version));
} elseif (null === $special && $i === 0 && false === strpos($match, '.') && is_numeric($match)) {
$match = isset($matches[$i + 1]) && (' - ' === $matches[$i + 1] || '-' === $matches[$i + 1])
Expand Down Expand Up @@ -209,6 +210,9 @@ protected function matchRangeTokenStep5($i, $match, array &$matches, &$special,
$matches[$i] = $replace
? SemverUtil::replaceAlias($matches[$i], $replace)
: $matches[$i];
$matches[$i] .= '~' === $special && in_array($replace, array('<', '>'))
? ','.$replace.$matches[$i]
: '';
$special = null;
$replace = null;
}
Expand Down
1 change: 1 addition & 0 deletions Tests/Converter/SemverConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public function getTestRanges()
array('~ 1.2', '~1.2'),
array('~ 1', '~1'),
array('^ 1.2.3', '>=1.2.3,<2.0.0'),
array('~> 1.2.3', '~1.2.3,>1.2.3'),
array('1.2.3 - 2.3.4', '>=1.2.3,<=2.3.4'),
array('1.0.0 - 1.3.x', '>=1.0.0,<1.4.0'),
array('1.0 - 1.x', '>=1.0,<2.0'),
Expand Down

0 comments on commit 0bfdd30

Please sign in to comment.