Skip to content

Commit

Permalink
Fix invalid conversion of semver with a null value
Browse files Browse the repository at this point in the history
  • Loading branch information
francoispluchino committed Oct 11, 2014
1 parent 3aedb80 commit c8c0cf1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Converter/SemverConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class SemverConverter implements VersionConverterInterface
*/
public function convertVersion($version)
{
if ('latest' === $version) {
return 'default';
if (in_array($version, array(null, '', 'latest'))) {
return '*';
}

$prefix = preg_match('/^[a-z]/', $version) ? substr($version, 0, 1) : '';
Expand Down
6 changes: 4 additions & 2 deletions Tests/Converter/SemverConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function testConverter($semver, $composer)
{
$this->assertEquals($composer, $this->converter->convertVersion($semver));

if (!ctype_alpha($semver)) {
if (!ctype_alpha($semver) && !in_array($semver, array(null, ''))) {
$this->assertEquals('v' . $composer, $this->converter->convertVersion('v' . $semver));
}
}
Expand Down Expand Up @@ -82,7 +82,9 @@ public function getTestVersions()
array('1.2.3-build2012', '1.2.3-patch2012'),
array('1.2.3+build.2012', '1.2.3-patch.2012'),
array('1.2.3-build.2012', '1.2.3-patch.2012'),
array('latest', 'default'),
array('latest', '*'),
array(null, '*'),
array('', '*'),
);
}

Expand Down

0 comments on commit c8c0cf1

Please sign in to comment.