Skip to content

Commit

Permalink
fix: fix range regexp to handle version with multiple digits
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg committed Dec 17, 2018
1 parent 89663d3 commit 9a04e64
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/utils.js
Expand Up @@ -31,11 +31,11 @@ function isMaintenanceRange(range) {
}

function getUpperBound(range) {
return semver.valid(range) ? range : ((semver.validRange(range) || '').match(/<(\d\.\d\.\d)$/) || [])[1];
return semver.valid(range) ? range : ((semver.validRange(range) || '').match(/<(\d+\.\d+\.\d+)$/) || [])[1];
}

function getLowerBound(range) {
return ((semver.validRange(range) || '').match(/(\d\.\d\.\d)/) || [])[1];
return ((semver.validRange(range) || '').match(/(\d+\.\d+\.\d+)/) || [])[1];
}

function highest(version1, version2) {
Expand Down
12 changes: 12 additions & 0 deletions test/utils.test.js
Expand Up @@ -70,18 +70,30 @@ test('isMaintenanceRange', t => {

test('getUpperBound', t => {
t.is(getUpperBound('1.x.x'), '2.0.0');
t.is(getUpperBound('1.X.X'), '2.0.0');
t.is(getUpperBound('10.x.x'), '11.0.0');
t.is(getUpperBound('1.x'), '2.0.0');
t.is(getUpperBound('10.x'), '11.0.0');
t.is(getUpperBound('1.0.x'), '1.1.0');
t.is(getUpperBound('10.0.x'), '10.1.0');
t.is(getUpperBound('10.10.x'), '10.11.0');
t.is(getUpperBound('1.0.0'), '1.0.0');
t.is(getUpperBound('10.0.0'), '10.0.0');

t.is(getUpperBound('foo'), undefined);
});

test('getLowerBound', t => {
t.is(getLowerBound('1.x.x'), '1.0.0');
t.is(getLowerBound('1.X.X'), '1.0.0');
t.is(getLowerBound('10.x.x'), '10.0.0');
t.is(getLowerBound('1.x'), '1.0.0');
t.is(getLowerBound('10.x'), '10.0.0');
t.is(getLowerBound('1.0.x'), '1.0.0');
t.is(getLowerBound('10.0.x'), '10.0.0');
t.is(getLowerBound('1.10.x'), '1.10.0');
t.is(getLowerBound('1.0.0'), '1.0.0');
t.is(getLowerBound('10.0.0'), '10.0.0');

t.is(getLowerBound('foo'), undefined);
});
Expand Down

0 comments on commit 9a04e64

Please sign in to comment.