-
Notifications
You must be signed in to change notification settings - Fork 493
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 <luke@lukekarrys.com> Co-authored-by: joaomoreno <mail@joaomoreno.com>
- 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
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() | ||
}) |