Skip to content

Commit

Permalink
Mimic the behavior of NPM and Bower when comparing versions
Browse files Browse the repository at this point in the history
constructed by 1 or 2 groups of numbers.

Versions as "1", "7.9", "v4" and "v98.2" are perfectly valid
and both Bower and NPM expand those to, accordingly, "1.*",
"7.9.*", "v4.*" and "v98.2.*". Until now this plugin
failed at doing so, which causes quite some failures when
trying to install packages that use that syntax (npmconf,
just to name one).

This commit fixes that by adding a single regex replace
that matches groups of numbers and appends a ".*". Also,
the regex keeps in mind that other type of versions,
such as "~2" or ">=4.5" don't need to be expanded.

Also note that this fix will not break current unit
tests.
  • Loading branch information
alexandernst committed Jun 3, 2015
1 parent 3c7c986 commit e982d0d
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions Converter/SemverConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function convertVersion($version)
public function convertRange($range)
{
$range = $this->cleanRange(strtolower($range));
$range = preg_replace('/(?<!\S)[vV]?\d+(?:\.\d+)?(?!\S)/', '${0}.*', $range);

return $this->matchRange($range);
}
Expand Down

0 comments on commit e982d0d

Please sign in to comment.