Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Handle caret for 0.* versions as exact match

  • Loading branch information...
commit 5705a9713fb1bd775e262c6d94028fb976eaa7ab 1 parent 73b8fa4
@agnoster agnoster authored isaacs committed
Showing with 18 additions and 6 deletions.
  1. +3 −0  README.md
  2. +9 −6 semver.js
  3. +6 −0 test/index.js
View
3  README.md
@@ -65,6 +65,9 @@ The following range styles are supported:
prerelease) will be supported up to, but not including, the next
major version (or its prereleases). `1.5.1` will satisfy `^1.2.3`,
while `1.2.2` and `2.0.0-beta` will not.
+* `^0.1.3` := `=0.1.3` Since 0.x versions are special in semver and
+ not guaranteed to be compatible in any way with each other, they are
+ handled as exact matches by the caret operator.
* `~1.2` := `>=1.2.0-0 <1.3.0-0` "Any version starting with 1.2"
* `^1.2` := `>=1.2.0-0 <2.0.0-0` "Any version compatible with 1.2"
* `1.2.x` := `>=1.2.0-0 <1.3.0-0` "Any version starting with 1.2"
View
15 semver.js
@@ -735,17 +735,20 @@ function replaceCaret(comp, loose) {
else if (isX(m))
ret = '>=' + M + '.0.0-0 <' + (+M + 1) + '.0.0-0';
else if (isX(p))
- // ~1.2 == >=1.2.0- <1.3.0-
- ret = '>=' + M + '.' + m + '.0-0 <' + (+M + 1) + '.0.0-0';
+ if (M === '0') ret = '>=' + M + '.' + m + '.0-0 <' + M + '.' + (+m + 1) + '.0-0';
+ // ^1.2 == >=1.2.0- <2.0.0-
+ else ret = '>=' + M + '.' + m + '.0-0 <' + (+M + 1) + '.0.0-0';
else if (pr) {
debug('replaceCaret pr', pr);
if (pr.charAt(0) !== '-')
pr = '-' + pr;
- ret = '>=' + M + '.' + m + '.' + p + pr +
- ' <' + (+M + 1) + '.0.0-0';
+ if (M === '0') ret = '=' + M + '.' + m + '.' + p + pr
+ else ret = '>=' + M + '.' + m + '.' + p + pr +
+ ' <' + (+M + 1) + '.0.0-0';
} else
- // ~1.2.3 == >=1.2.3-0 <1.3.0-0
- ret = '>=' + M + '.' + m + '.' + p + '-0' +
+ if (M === '0') ret = '=' + M + '.' + m + '.' + p
+ // ^1.2.3 == >=1.2.3-0 <2.0.0-0
+ else ret = '>=' + M + '.' + m + '.' + p + '-0' +
' <' + (+M + 1) + '.0.0-0';
debug('caret return', ret);
View
6 test/index.js
@@ -210,6 +210,8 @@ test('\nrange tests', function(t) {
['>=1.2', '1.2.8'],
['^1.2.3', '1.8.1'],
['^1.2.3', '1.2.3-beta'],
+ ['^0.1.2', '0.1.2'],
+ ['^0.1', '0.1.2'],
['^1.2', '1.4.2']
].forEach(function(v) {
var range = v[0];
@@ -384,6 +386,10 @@ test('\nvalid range test', function(t) {
['^ 1', '>=1.0.0-0 <2.0.0-0'],
['^2.3', '>=2.3.0-0 <3.0.0-0'],
['^1.2.3-beta.4', '>=1.2.3-beta.4 <2.0.0-0'],
+ ['^0.1.2-test', '=0.1.2-test'],
+ ['^0.1.2', '=0.1.2'],
+ ['^0.1', '>=0.1.0-0 <0.2.0-0'],
+ ['^0', '>=0.0.0-0 <1.0.0-0'],
['<1', '<1.0.0-0'],
['< 1', '<1.0.0-0'],
['>=1', '>=1.0.0-0'],
Please sign in to comment.
Something went wrong with that request. Please try again.