diff --git a/.gitignore b/.gitignore index fc43a6edd..a0994810c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ vendor/ .php_cs.cache composer.lock +.idea diff --git a/src/VersionParser.php b/src/VersionParser.php index 8732207f1..928455892 100644 --- a/src/VersionParser.php +++ b/src/VersionParser.php @@ -106,6 +106,13 @@ public function normalize($version, $fullVersion = null) $fullVersion = $version; } + if (preg_match('{^(\^[^,\s]++) ++as ++([^,\s\^]++)$}', $version, $match) || + preg_match('{^([^,\s]++) ++as ++(\^[^,\s\^]++)$}', $version, $match) || + preg_match('{^([^,\s]++) ++as ++(\~[^,\s\^]++)$}', $version, $match) || + preg_match('{^(\~[^,\s]++) ++as ++([^,\s\^]++)$}', $version, $match)) { + throw new \UnexpectedValueException('the alias must be an exact version'); + } + // strip off aliasing if (preg_match('{^([^,\s]++) ++as ++([^,\s]++)$}', $version, $match)) { $version = $match[1]; diff --git a/tests/VersionParserTest.php b/tests/VersionParserTest.php index 3fdee600c..8cb41ebe0 100644 --- a/tests/VersionParserTest.php +++ b/tests/VersionParserTest.php @@ -123,6 +123,10 @@ public function failingNormalizedVersions() 'non-dev arbitrary' => array('feature-foo'), 'metadata w/ space' => array('1.0.0+foo bar'), 'maven style release' => array('1.0.1-SNAPSHOT'), + 'Alias and caret on left side' => array('^1.0.0+foo as 2.0'), + 'Alias and caret on right side' => array('1.0.0+foo as ^2.0'), + 'Alias and tilde on left side' => array('~1.0.0+foo as 2.0'), + 'Alias and tilde on right side' => array('1.0.0+foo as ~2.0'), ); }