Permalink
Browse files

Trim comparators properly

Remove the extra space

Fixes GH-42
  • Loading branch information...
1 parent ff7e65e commit 25e438134ec8442531f05b1360b56fff283a6e45 @isaacs isaacs committed Jul 24, 2013
Showing with 6 additions and 6 deletions.
  1. +3 −4 semver.js
  2. +3 −2 test/index.js
View
@@ -180,13 +180,12 @@ src[COMPARATOR] = '^' + src[GTLT] + '\\s*(' + FULLPLAIN + ')$|^$';
// An expression to strip any whitespace between the gtlt and the thing
// it modifies, so that `> 1.2.3` ==> `>1.2.3`
var COMPARATORTRIM = R++;
-src[COMPARATORTRIM] = src[GTLT] +
+src[COMPARATORTRIM] = '(\\s*)' + src[GTLT] +
'\\s*(' + LOOSEPLAIN + '|' + src[XRANGEPLAIN] + ')';
// this one has to use the /g flag
re[COMPARATORTRIM] = new RegExp(src[COMPARATORTRIM], 'g');
-
-var comparatorTrimReplace = '$1$2 ';
+var comparatorTrimReplace = '$1$2$3';
// Something like `1.2.3 - 1.2.4`
@@ -598,7 +597,7 @@ Range.prototype.parseRange = function(range) {
debug('hyphen replace', range);
// `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
range = range.replace(re[COMPARATORTRIM], comparatorTrimReplace);
- debug('comparator trim', range);
+ debug('comparator trim', range, re[COMPARATORTRIM]);
// `~ 1.2.3` => `~1.2.3`
range = range.replace(re[TILDETRIM], tildeTrimReplace);
View
@@ -269,7 +269,8 @@ test('\nnegative range tests', function(t) {
['=1.2.3', '1.2.3-beta'],
['>1.2', '1.2.8'],
// invalid ranges never satisfied!
- ['blerg', '1.2.3']
+ ['blerg', '1.2.3'],
+ ['git+https://user:password0123@github.com/foo', '123.0.0', true]
].forEach(function(v) {
var range = v[0];
var ver = v[1];
@@ -529,4 +530,4 @@ test('\nmax satisfying', function(t) {
t.equal(actual, expect);
});
t.end();
-});
+});

0 comments on commit 25e4381

Please sign in to comment.