From 0bfdd307d2cddbc42c634b14247f3f3a8525b836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Pluchino?= Date: Sun, 9 Apr 2017 13:49:10 +0200 Subject: [PATCH] Fix the invalid operator ~> --- Converter/SemverConverter.php | 6 +++++- Tests/Converter/SemverConverterTest.php | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Converter/SemverConverter.php b/Converter/SemverConverter.php index 8b61727a..63573109 100644 --- a/Converter/SemverConverter.php +++ b/Converter/SemverConverter.php @@ -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', '^'))) { @@ -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]) @@ -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; } diff --git a/Tests/Converter/SemverConverterTest.php b/Tests/Converter/SemverConverterTest.php index 197a1e6c..45ea4655 100644 --- a/Tests/Converter/SemverConverterTest.php +++ b/Tests/Converter/SemverConverterTest.php @@ -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'),