-
Notifications
You must be signed in to change notification settings - Fork 492
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: better handling of whitespace (#585)
This is a backport of the following commits squashed to land on `release/v5`: - 717534e - abdd93d - cc6fde2 - 99d8287 Ref: #564 Co-authored-by: Luke Karrys <[email protected]> Co-authored-by: joaomoreno <[email protected]>
- Loading branch information
1 parent
deb5ad5
commit 2f8fd41
Showing
4 changed files
with
156 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -327,7 +327,8 @@ test('negative range tests', function (t) { | |
['blerg', '1.2.3'], | ||
['git+https://user:[email protected]/foo', '123.0.0', true], | ||
['^1.2.3', '2.0.0-pre'], | ||
['^1.2.3', false] | ||
['^1.2.3', false], | ||
['== 1.0.0 || foo', '2.0.0', { loose: true }] | ||
].forEach(function (v) { | ||
var range = v[0] | ||
var ver = v[1] | ||
|
@@ -980,3 +981,12 @@ test('really big numeric prerelease value', function (t) { | |
t.strictSame(r.prerelease, [ 'beta', '90071992547409910' ]) | ||
t.end() | ||
}) | ||
|
||
test('long build id', function (t) { | ||
var longBuild = '-928490632884417731e7af463c92b034d6a78268fc993bcb88a57944' | ||
var shortVersion = '1.1.1' | ||
var longVersion = Number.MAX_SAFE_INTEGER + '.' + Number.MAX_SAFE_INTEGER + '.' + Number.MAX_SAFE_INTEGER | ||
t.equal(semver.valid(shortVersion + longBuild), shortVersion + longBuild) | ||
t.equal(semver.valid(longVersion + longBuild), longVersion + longBuild) | ||
t.end() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
var test = require('tap').test | ||
var semver = require('../') | ||
|
||
test('has a list of src, re, and safeRe', function (t) { | ||
semver.re.forEach(function (r) { return t.match(r, RegExp, 'regexps are regexps') }) | ||
semver.src.forEach(function (s) { return t.match(s, String, 'src is strings') }) | ||
|
||
semver.safeRe.forEach(function (r) { | ||
t.notMatch(r.source, '\\s+', 'safe regex do not contain greedy whitespace') | ||
t.notMatch(r.source, '\\s*', 'safe regex do not contain greedy whitespace') | ||
}) | ||
|
||
t.end() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
var test = require('tap').test | ||
var semver = require('../') | ||
|
||
var validRange = semver.validRange | ||
var SemVer = semver.SemVer | ||
var Range = semver.Range | ||
var Comparator = semver.Comparator | ||
var minVersion = semver.minVersion | ||
var minSatisfying = semver.minSatisfying | ||
var maxSatisfying = semver.maxSatisfying | ||
|
||
function s(n, char) { | ||
if (!n) { | ||
n = 500000 | ||
} | ||
if (!char) { | ||
char = ' ' | ||
} | ||
var c = '' | ||
for (var i = 0; i < n; i++) { | ||
c += char | ||
} | ||
return c | ||
} | ||
|
||
test('regex dos via range whitespace', function (t) { | ||
// a range with this much whitespace would take a few minutes to process if | ||
// any redos susceptible regexes were used. there is a global tap timeout per | ||
// file set in the package.json that will error if this test takes too long. | ||
var r = `1.2.3 ${s()} <1.3.0` | ||
|
||
t.equal(new Range(r).range, '1.2.3 <1.3.0') | ||
t.equal(validRange(r), '1.2.3 <1.3.0') | ||
t.equal(minVersion(r).version, '1.2.3') | ||
t.equal(minSatisfying(['1.2.3'], r), '1.2.3') | ||
t.equal(maxSatisfying(['1.2.3'], r), '1.2.3') | ||
|
||
t.end() | ||
}) | ||
|
||
test('range with 0', function (t) { | ||
var r = `1.2.3 ${s(null, '0')} <1.3.0` | ||
t.throws(function () { return new Range(r).range }) | ||
t.equal(validRange(r), null) | ||
t.throws(function () { return minVersion(r).version }) | ||
t.equal(minSatisfying(['1.2.3'], r), null) | ||
t.equal(maxSatisfying(['1.2.3'], r), null) | ||
t.end() | ||
}) | ||
|
||
test('semver version', function (t) { | ||
var v = `${s(125)}1.2.3${s(125)}` | ||
var tooLong = `${s()}1.2.3${s()}` | ||
t.equal(new SemVer(v).version, '1.2.3') | ||
t.throws(function () { return new SemVer(tooLong) }) | ||
t.end() | ||
}) | ||
|
||
test('comparator', function (t) { | ||
var c = `${s()}<${s()}1.2.3${s()}` | ||
t.equal(new Comparator(c).value, '<1.2.3') | ||
t.end() | ||
}) |