Browse files

Trim caret and tildes globally

  • Loading branch information...
1 parent ea1b9e3 commit 0af8ac2edab845663872bc699bde858e4a84bf92 @isaacs isaacs committed Jul 29, 2013
Showing with 10 additions and 6 deletions.
  1. +6 −4 semver.js
  2. +4 −2 test/index.js
View
10 semver.js
@@ -161,8 +161,9 @@ var LONETILDE = R++;
src[LONETILDE] = '(?:~>?)';
var TILDETRIM = R++;
-src[TILDETRIM] = src[LONETILDE] + '\\s+';
-var tildeTrimReplace = '~';
+src[TILDETRIM] = '(\\s*)' + src[LONETILDE] + '\\s+';
+re[TILDETRIM] = new RegExp(src[TILDETRIM], 'g');
+var tildeTrimReplace = '$1~';
var TILDE = R++;
src[TILDE] = '^' + src[LONETILDE] + src[XRANGEPLAIN] + '$';
@@ -175,8 +176,9 @@ var LONECARET = R++;
src[LONECARET] = '(?:\\^)';
var CARETTRIM = R++;
-src[CARETTRIM] = src[LONECARET] + '\s+';
-var caretTrimReplace = '$1';
+src[CARETTRIM] = '(\\s*)' + src[LONECARET] + '\\s+';
+re[CARETTRIM] = new RegExp(src[CARETTRIM], 'g');
+var caretTrimReplace = '$1^';
var CARET = R++;
src[CARET] = '^' + src[LONECARET] + src[XRANGEPLAIN] + '$';
View
6 test/index.js
@@ -212,7 +212,8 @@ test('\nrange tests', function(t) {
['^1.2.3', '1.2.3-beta'],
['^0.1.2', '0.1.2'],
['^0.1', '0.1.2'],
- ['^1.2', '1.4.2']
+ ['^1.2', '1.4.2'],
+ ['^1.2 ^1', '1.4.2']
].forEach(function(v) {
var range = v[0];
var ver = v[1];
@@ -402,7 +403,8 @@ test('\nvalid range test', function(t) {
['>01.02.03', '>1.2.3', true],
['>01.02.03', null],
['~1.2.3beta', '>=1.2.3-beta <1.3.0-0', true],
- ['~1.2.3beta', null]
+ ['~1.2.3beta', null],
+ ['^ 1.2 ^ 1', '>=1.2.0-0 <2.0.0-0 >=1.0.0-0 <2.0.0-0']
].forEach(function(v) {
var pre = v[0];
var wanted = v[1];

0 comments on commit 0af8ac2

Please sign in to comment.