Skip to content

Commit

Permalink
Don't try to parse aliases versions which doesn't contain exact version
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianosferreira committed Jan 6, 2020
1 parent 2667cf1 commit cc9fca3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vendor/
.php_cs.cache
composer.lock
.idea
7 changes: 7 additions & 0 deletions src/VersionParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
4 changes: 4 additions & 0 deletions tests/VersionParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
);
}

Expand Down

0 comments on commit cc9fca3

Please sign in to comment.