Skip to content

Commit

Permalink
Only allow a . to start a prerelease if the prerelease starts with a …
Browse files Browse the repository at this point in the history
…non-number

Allowing 1.2.3.4 is confusing and weird.

However, 1.2.3.beta should be allowed.
  • Loading branch information
isaacs committed Feb 8, 2017
1 parent 0362a0f commit c082957
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
5 changes: 3 additions & 2 deletions semver.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ var PRERELEASEIDENTIFIERLOOSE = R++;
src[PRERELEASEIDENTIFIERLOOSE] = '(?:' + src[NUMERICIDENTIFIERLOOSE] +
'|' + src[NONNUMERICIDENTIFIER] + ')';


// ## Pre-release Version
// Hyphen, followed by one or more dot-separated pre-release version
// identifiers.
Expand All @@ -91,8 +90,10 @@ var PRERELEASE = R++;
src[PRERELEASE] = '(?:-(' + src[PRERELEASEIDENTIFIER] +
'(?:\\.' + src[PRERELEASEIDENTIFIER] + ')*))';

// Allow a . or a missing -, but only if the first pr id is non-numeric
var PRERELEASELOOSE = R++;
src[PRERELEASELOOSE] = '(?:[-\.]?(' + src[PRERELEASEIDENTIFIERLOOSE] +
src[PRERELEASELOOSE] = '(?:(?:-|\\.*(?=[a-zA-Z-]))' +
'(' + src[PRERELEASEIDENTIFIERLOOSE] +
'(?:\\.' + src[PRERELEASEIDENTIFIERLOOSE] + ')*))';

// ## Build Metadata Identifier
Expand Down
13 changes: 11 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -666,14 +666,19 @@ test('comparators test', function(t) {

test('invalid version numbers', function(t) {
['1.2.3.4',
'1.2.34.5',
'1.2.3..4',
'NOT VALID',
1.2,
null,
'Infinity.NaN.Infinity'
].forEach(function(v) {
t.throws(function() {
new SemVer(v);
}, {name:'TypeError', message:'Invalid Version: ' + v});
}, 'should be invalid: '+v, {name:'TypeError', message:'Invalid Version: ' + v});
t.throws(function() {
new SemVer(v, true);
}, 'should be invalid: '+v, {name:'TypeError', message:'Invalid Version: ' + v});
});

t.end();
Expand All @@ -686,7 +691,11 @@ test('strict vs loose version numbers', function(t) {
[' =1.2.3', '1.2.3'],
['1.2.3foo', '1.2.3-foo'],
['1.2.3.foo', '1.2.3-foo'],
['1.2.3.4.5.6.7.8.9.0', '1.2.3-4.5.6.7.8.9.0']
['1.2.3.x4.5.6.7.8.9.0', '1.2.3-x4.5.6.7.8.9.0'],
['1.2.3.x', '1.2.3-x'],
['1.2.3.-x', '1.2.3--x'],
['1.2.3...x', '1.2.3-x'],
['1.2.3...-x', '1.2.3--x']
].forEach(function(v) {
var loose = v[0];
var strict = v[1];
Expand Down

0 comments on commit c082957

Please sign in to comment.