diff options
author | Forrest L Norvell <forrest@npmjs.com> | 2015-03-27 08:22:00 +0300 |
---|---|---|
committer | Forrest L Norvell <forrest@npmjs.com> | 2015-03-27 08:22:00 +0300 |
commit | 0dc68757cffd5397c280bc71365d106523a5a052 (patch) | |
tree | 79f2e7580a6335a80ef69412d045400186abfdc8 /node_modules/semver/semver.js | |
parent | a840a13bbf0330157536381ea8e58d0bd93b4c05 (diff) |
semver@4.3.2
256 characters ought to be enough for anybody.
Diffstat (limited to 'node_modules/semver/semver.js')
-rw-r--r-- | node_modules/semver/semver.js | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/node_modules/semver/semver.js b/node_modules/semver/semver.js index 544bc8312..d265b568e 100644 --- a/node_modules/semver/semver.js +++ b/node_modules/semver/semver.js @@ -20,6 +20,9 @@ if (typeof module === 'object' && module.exports === exports) // Not necessarily the package version of this code. exports.SEMVER_SPEC_VERSION = '2.0.0'; +var MAX_LENGTH = 256; +var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991; + // The actual regexps go on exports.re var re = exports.re = []; var src = exports.src = []; @@ -233,8 +236,18 @@ for (var i = 0; i < R; i++) { exports.parse = parse; function parse(version, loose) { + if (version.length > MAX_LENGTH) + return null; + var r = loose ? re[LOOSE] : re[FULL]; - return (r.test(version)) ? new SemVer(version, loose) : null; + if (!r.test(version)) + return null; + + try { + return new SemVer(version, loose); + } catch (er) { + return null; + } } exports.valid = valid; @@ -262,6 +275,9 @@ function SemVer(version, loose) { throw new TypeError('Invalid Version: ' + version); } + if (version.length > MAX_LENGTH) + throw new TypeError('version is longer than ' + MAX_LENGTH + ' characters') + if (!(this instanceof SemVer)) return new SemVer(version, loose); @@ -279,6 +295,15 @@ function SemVer(version, loose) { this.minor = +m[2]; this.patch = +m[3]; + if (this.major > MAX_SAFE_INTEGER || this.major < 0) + throw new TypeError('Invalid major version') + + if (this.minor > MAX_SAFE_INTEGER || this.minor < 0) + throw new TypeError('Invalid minor version') + + if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) + throw new TypeError('Invalid patch version') + // numberify any prerelease numeric ids if (!m[4]) this.prerelease = []; |