Skip to content

Commit 0bb97b1

Browse files
Rebuild after updating Semver
1 parent 4220624 commit 0bb97b1

File tree

2 files changed

+142
-48
lines changed

2 files changed

+142
-48
lines changed

dist/cache-save/index.js

+71-24
Original file line numberDiff line numberDiff line change
@@ -51331,8 +51331,11 @@ var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER ||
5133151331
// Max safe segment length for coercion.
5133251332
var MAX_SAFE_COMPONENT_LENGTH = 16
5133351333

51334+
var MAX_SAFE_BUILD_LENGTH = MAX_LENGTH - 6
51335+
5133451336
// The actual regexps go on exports.re
5133551337
var re = exports.re = []
51338+
var safeRe = exports.safeRe = []
5133651339
var src = exports.src = []
5133751340
var t = exports.tokens = {}
5133851341
var R = 0
@@ -51341,6 +51344,31 @@ function tok (n) {
5134151344
t[n] = R++
5134251345
}
5134351346

51347+
var LETTERDASHNUMBER = '[a-zA-Z0-9-]'
51348+
51349+
// Replace some greedy regex tokens to prevent regex dos issues. These regex are
51350+
// used internally via the safeRe object since all inputs in this library get
51351+
// normalized first to trim and collapse all extra whitespace. The original
51352+
// regexes are exported for userland consumption and lower level usage. A
51353+
// future breaking change could export the safer regex only with a note that
51354+
// all input should have extra whitespace removed.
51355+
var safeRegexReplacements = [
51356+
['\\s', 1],
51357+
['\\d', MAX_LENGTH],
51358+
[LETTERDASHNUMBER, MAX_SAFE_BUILD_LENGTH],
51359+
]
51360+
51361+
function makeSafeRe (value) {
51362+
for (var i = 0; i < safeRegexReplacements.length; i++) {
51363+
var token = safeRegexReplacements[i][0]
51364+
var max = safeRegexReplacements[i][1]
51365+
value = value
51366+
.split(token + '*').join(token + '{0,' + max + '}')
51367+
.split(token + '+').join(token + '{1,' + max + '}')
51368+
}
51369+
return value
51370+
}
51371+
5134451372
// The following Regular Expressions can be used for tokenizing,
5134551373
// validating, and parsing SemVer version strings.
5134651374

@@ -51350,14 +51378,14 @@ function tok (n) {
5135051378
tok('NUMERICIDENTIFIER')
5135151379
src[t.NUMERICIDENTIFIER] = '0|[1-9]\\d*'
5135251380
tok('NUMERICIDENTIFIERLOOSE')
51353-
src[t.NUMERICIDENTIFIERLOOSE] = '[0-9]+'
51381+
src[t.NUMERICIDENTIFIERLOOSE] = '\\d+'
5135451382

5135551383
// ## Non-numeric Identifier
5135651384
// Zero or more digits, followed by a letter or hyphen, and then zero or
5135751385
// more letters, digits, or hyphens.
5135851386

5135951387
tok('NONNUMERICIDENTIFIER')
51360-
src[t.NONNUMERICIDENTIFIER] = '\\d*[a-zA-Z-][a-zA-Z0-9-]*'
51388+
src[t.NONNUMERICIDENTIFIER] = '\\d*[a-zA-Z-]' + LETTERDASHNUMBER + '*'
5136151389

5136251390
// ## Main Version
5136351391
// Three dot-separated numeric identifiers.
@@ -51399,7 +51427,7 @@ src[t.PRERELEASELOOSE] = '(?:-?(' + src[t.PRERELEASEIDENTIFIERLOOSE] +
5139951427
// Any combination of digits, letters, or hyphens.
5140051428

5140151429
tok('BUILDIDENTIFIER')
51402-
src[t.BUILDIDENTIFIER] = '[0-9A-Za-z-]+'
51430+
src[t.BUILDIDENTIFIER] = LETTERDASHNUMBER + '+'
5140351431

5140451432
// ## Build Metadata
5140551433
// Plus sign, followed by one or more period-separated build metadata
@@ -51479,6 +51507,7 @@ src[t.COERCE] = '(^|[^\\d])' +
5147951507
'(?:$|[^\\d])'
5148051508
tok('COERCERTL')
5148151509
re[t.COERCERTL] = new RegExp(src[t.COERCE], 'g')
51510+
safeRe[t.COERCERTL] = new RegExp(makeSafeRe(src[t.COERCE]), 'g')
5148251511

5148351512
// Tilde ranges.
5148451513
// Meaning is "reasonably at or greater than"
@@ -51488,6 +51517,7 @@ src[t.LONETILDE] = '(?:~>?)'
5148851517
tok('TILDETRIM')
5148951518
src[t.TILDETRIM] = '(\\s*)' + src[t.LONETILDE] + '\\s+'
5149051519
re[t.TILDETRIM] = new RegExp(src[t.TILDETRIM], 'g')
51520+
safeRe[t.TILDETRIM] = new RegExp(makeSafeRe(src[t.TILDETRIM]), 'g')
5149151521
var tildeTrimReplace = '$1~'
5149251522

5149351523
tok('TILDE')
@@ -51503,6 +51533,7 @@ src[t.LONECARET] = '(?:\\^)'
5150351533
tok('CARETTRIM')
5150451534
src[t.CARETTRIM] = '(\\s*)' + src[t.LONECARET] + '\\s+'
5150551535
re[t.CARETTRIM] = new RegExp(src[t.CARETTRIM], 'g')
51536+
safeRe[t.CARETTRIM] = new RegExp(makeSafeRe(src[t.CARETTRIM]), 'g')
5150651537
var caretTrimReplace = '$1^'
5150751538

5150851539
tok('CARET')
@@ -51524,6 +51555,7 @@ src[t.COMPARATORTRIM] = '(\\s*)' + src[t.GTLT] +
5152451555

5152551556
// this one has to use the /g flag
5152651557
re[t.COMPARATORTRIM] = new RegExp(src[t.COMPARATORTRIM], 'g')
51558+
safeRe[t.COMPARATORTRIM] = new RegExp(makeSafeRe(src[t.COMPARATORTRIM]), 'g')
5152751559
var comparatorTrimReplace = '$1$2$3'
5152851560

5152951561
// Something like `1.2.3 - 1.2.4`
@@ -51552,6 +51584,14 @@ for (var i = 0; i < R; i++) {
5155251584
debug(i, src[i])
5155351585
if (!re[i]) {
5155451586
re[i] = new RegExp(src[i])
51587+
51588+
// Replace all greedy whitespace to prevent regex dos issues. These regex are
51589+
// used internally via the safeRe object since all inputs in this library get
51590+
// normalized first to trim and collapse all extra whitespace. The original
51591+
// regexes are exported for userland consumption and lower level usage. A
51592+
// future breaking change could export the safer regex only with a note that
51593+
// all input should have extra whitespace removed.
51594+
safeRe[i] = new RegExp(makeSafeRe(src[i]))
5155551595
}
5155651596
}
5155751597

@@ -51576,7 +51616,7 @@ function parse (version, options) {
5157651616
return null
5157751617
}
5157851618

51579-
var r = options.loose ? re[t.LOOSE] : re[t.FULL]
51619+
var r = options.loose ? safeRe[t.LOOSE] : safeRe[t.FULL]
5158051620
if (!r.test(version)) {
5158151621
return null
5158251622
}
@@ -51631,7 +51671,7 @@ function SemVer (version, options) {
5163151671
this.options = options
5163251672
this.loose = !!options.loose
5163351673

51634-
var m = version.trim().match(options.loose ? re[t.LOOSE] : re[t.FULL])
51674+
var m = version.trim().match(options.loose ? safeRe[t.LOOSE] : safeRe[t.FULL])
5163551675

5163651676
if (!m) {
5163751677
throw new TypeError('Invalid Version: ' + version)
@@ -52076,6 +52116,7 @@ function Comparator (comp, options) {
5207652116
return new Comparator(comp, options)
5207752117
}
5207852118

52119+
comp = comp.trim().split(/\s+/).join(' ')
5207952120
debug('comparator', comp, options)
5208052121
this.options = options
5208152122
this.loose = !!options.loose
@@ -52092,7 +52133,7 @@ function Comparator (comp, options) {
5209252133

5209352134
var ANY = {}
5209452135
Comparator.prototype.parse = function (comp) {
52095-
var r = this.options.loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR]
52136+
var r = this.options.loose ? safeRe[t.COMPARATORLOOSE] : safeRe[t.COMPARATOR]
5209652137
var m = comp.match(r)
5209752138

5209852139
if (!m) {
@@ -52216,17 +52257,24 @@ function Range (range, options) {
5221652257
this.loose = !!options.loose
5221752258
this.includePrerelease = !!options.includePrerelease
5221852259

52219-
// First, split based on boolean or ||
52260+
// First reduce all whitespace as much as possible so we do not have to rely
52261+
// on potentially slow regexes like \s*. This is then stored and used for
52262+
// future error messages as well.
5222052263
this.raw = range
52221-
this.set = range.split(/\s*\|\|\s*/).map(function (range) {
52264+
.trim()
52265+
.split(/\s+/)
52266+
.join(' ')
52267+
52268+
// First, split based on boolean or ||
52269+
this.set = this.raw.split('||').map(function (range) {
5222252270
return this.parseRange(range.trim())
5222352271
}, this).filter(function (c) {
5222452272
// throw out any that are not relevant for whatever reason
5222552273
return c.length
5222652274
})
5222752275

5222852276
if (!this.set.length) {
52229-
throw new TypeError('Invalid SemVer Range: ' + range)
52277+
throw new TypeError('Invalid SemVer Range: ' + this.raw)
5223052278
}
5223152279

5223252280
this.format()
@@ -52245,28 +52293,27 @@ Range.prototype.toString = function () {
5224552293

5224652294
Range.prototype.parseRange = function (range) {
5224752295
var loose = this.options.loose
52248-
range = range.trim()
5224952296
// `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
52250-
var hr = loose ? re[t.HYPHENRANGELOOSE] : re[t.HYPHENRANGE]
52297+
var hr = loose ? safeRe[t.HYPHENRANGELOOSE] : safeRe[t.HYPHENRANGE]
5225152298
range = range.replace(hr, hyphenReplace)
5225252299
debug('hyphen replace', range)
5225352300
// `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
52254-
range = range.replace(re[t.COMPARATORTRIM], comparatorTrimReplace)
52255-
debug('comparator trim', range, re[t.COMPARATORTRIM])
52301+
range = range.replace(safeRe[t.COMPARATORTRIM], comparatorTrimReplace)
52302+
debug('comparator trim', range, safeRe[t.COMPARATORTRIM])
5225652303

5225752304
// `~ 1.2.3` => `~1.2.3`
52258-
range = range.replace(re[t.TILDETRIM], tildeTrimReplace)
52305+
range = range.replace(safeRe[t.TILDETRIM], tildeTrimReplace)
5225952306

5226052307
// `^ 1.2.3` => `^1.2.3`
52261-
range = range.replace(re[t.CARETTRIM], caretTrimReplace)
52308+
range = range.replace(safeRe[t.CARETTRIM], caretTrimReplace)
5226252309

5226352310
// normalize spaces
5226452311
range = range.split(/\s+/).join(' ')
5226552312

5226652313
// At this point, the range is completely trimmed and
5226752314
// ready to be split into comparators.
5226852315

52269-
var compRe = loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR]
52316+
var compRe = loose ? safeRe[t.COMPARATORLOOSE] : safeRe[t.COMPARATOR]
5227052317
var set = range.split(' ').map(function (comp) {
5227152318
return parseComparator(comp, this.options)
5227252319
}, this).join(' ').split(/\s+/)
@@ -52366,7 +52413,7 @@ function replaceTildes (comp, options) {
5236652413
}
5236752414

5236852415
function replaceTilde (comp, options) {
52369-
var r = options.loose ? re[t.TILDELOOSE] : re[t.TILDE]
52416+
var r = options.loose ? safeRe[t.TILDELOOSE] : safeRe[t.TILDE]
5237052417
return comp.replace(r, function (_, M, m, p, pr) {
5237152418
debug('tilde', comp, _, M, m, p, pr)
5237252419
var ret
@@ -52407,7 +52454,7 @@ function replaceCarets (comp, options) {
5240752454

5240852455
function replaceCaret (comp, options) {
5240952456
debug('caret', comp, options)
52410-
var r = options.loose ? re[t.CARETLOOSE] : re[t.CARET]
52457+
var r = options.loose ? safeRe[t.CARETLOOSE] : safeRe[t.CARET]
5241152458
return comp.replace(r, function (_, M, m, p, pr) {
5241252459
debug('caret', comp, _, M, m, p, pr)
5241352460
var ret
@@ -52466,7 +52513,7 @@ function replaceXRanges (comp, options) {
5246652513

5246752514
function replaceXRange (comp, options) {
5246852515
comp = comp.trim()
52469-
var r = options.loose ? re[t.XRANGELOOSE] : re[t.XRANGE]
52516+
var r = options.loose ? safeRe[t.XRANGELOOSE] : safeRe[t.XRANGE]
5247052517
return comp.replace(r, function (ret, gtlt, M, m, p, pr) {
5247152518
debug('xRange', comp, ret, gtlt, M, m, p, pr)
5247252519
var xM = isX(M)
@@ -52541,7 +52588,7 @@ function replaceXRange (comp, options) {
5254152588
function replaceStars (comp, options) {
5254252589
debug('replaceStars', comp, options)
5254352590
// Looseness is ignored here. star is always as loose as it gets!
52544-
return comp.trim().replace(re[t.STAR], '')
52591+
return comp.trim().replace(safeRe[t.STAR], '')
5254552592
}
5254652593

5254752594
// This function is passed to string.replace(re[t.HYPHENRANGE])
@@ -52867,7 +52914,7 @@ function coerce (version, options) {
5286752914

5286852915
var match = null
5286952916
if (!options.rtl) {
52870-
match = version.match(re[t.COERCE])
52917+
match = version.match(safeRe[t.COERCE])
5287152918
} else {
5287252919
// Find the right-most coercible string that does not share
5287352920
// a terminus with a more left-ward coercible string.
@@ -52878,17 +52925,17 @@ function coerce (version, options) {
5287852925
// Stop when we get a match that ends at the string end, since no
5287952926
// coercible string can be more right-ward without the same terminus.
5288052927
var next
52881-
while ((next = re[t.COERCERTL].exec(version)) &&
52928+
while ((next = safeRe[t.COERCERTL].exec(version)) &&
5288252929
(!match || match.index + match[0].length !== version.length)
5288352930
) {
5288452931
if (!match ||
5288552932
next.index + next[0].length !== match.index + match[0].length) {
5288652933
match = next
5288752934
}
52888-
re[t.COERCERTL].lastIndex = next.index + next[1].length + next[2].length
52935+
safeRe[t.COERCERTL].lastIndex = next.index + next[1].length + next[2].length
5288952936
}
5289052937
// leave it in a clean state
52891-
re[t.COERCERTL].lastIndex = -1
52938+
safeRe[t.COERCERTL].lastIndex = -1
5289252939
}
5289352940

5289452941
if (match === null) {

0 commit comments

Comments
 (0)