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 e443591
Show file tree
Hide file tree
Showing 3 changed files with 8 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
5 changes: 5 additions & 0 deletions src/VersionParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ public function normalize($version, $fullVersion = null)
$fullVersion = $version;
}

if (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
2 changes: 2 additions & 0 deletions tests/VersionParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ 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'),
'Not exact version on alias on first part' => array('^1.0.0+foo as 2.0'),
'Not exact version on alias on second part' => array('1.0.0+foo as 2.0'),
);
}

Expand Down

0 comments on commit e443591

Please sign in to comment.