@@ -8604,6 +8604,7 @@ class Comparator {
8604
8604
}
8605
8605
}
8606
8606
8607
+ comp = comp . trim ( ) . split ( / \s + / ) . join ( ' ' )
8607
8608
debug ( 'comparator' , comp , options )
8608
8609
this . options = options
8609
8610
this . loose = ! ! options . loose
@@ -8721,7 +8722,7 @@ class Comparator {
8721
8722
module . exports = Comparator
8722
8723
8723
8724
const parseOptions = __nccwpck_require__ ( 785 )
8724
- const { re, t } = __nccwpck_require__ ( 9523 )
8725
+ const { safeRe : re , t } = __nccwpck_require__ ( 9523 )
8725
8726
const cmp = __nccwpck_require__ ( 5098 )
8726
8727
const debug = __nccwpck_require__ ( 427 )
8727
8728
const SemVer = __nccwpck_require__ ( 8088 )
@@ -8761,19 +8762,26 @@ class Range {
8761
8762
this . loose = ! ! options . loose
8762
8763
this . includePrerelease = ! ! options . includePrerelease
8763
8764
8764
- // First, split based on boolean or ||
8765
+ // First reduce all whitespace as much as possible so we do not have to rely
8766
+ // on potentially slow regexes like \s*. This is then stored and used for
8767
+ // future error messages as well.
8765
8768
this . raw = range
8766
- this . set = range
8769
+ . trim ( )
8770
+ . split ( / \s + / )
8771
+ . join ( ' ' )
8772
+
8773
+ // First, split on ||
8774
+ this . set = this . raw
8767
8775
. split ( '||' )
8768
8776
// map the range to a 2d array of comparators
8769
- . map ( r => this . parseRange ( r . trim ( ) ) )
8777
+ . map ( r => this . parseRange ( r ) )
8770
8778
// throw out any comparator lists that are empty
8771
8779
// this generally means that it was not a valid range, which is allowed
8772
8780
// in loose mode, but will still throw if the WHOLE range is invalid.
8773
8781
. filter ( c => c . length )
8774
8782
8775
8783
if ( ! this . set . length ) {
8776
- throw new TypeError ( `Invalid SemVer Range: ${ range } ` )
8784
+ throw new TypeError ( `Invalid SemVer Range: ${ this . raw } ` )
8777
8785
}
8778
8786
8779
8787
// if we have any that are not the null set, throw out null sets.
@@ -8799,9 +8807,7 @@ class Range {
8799
8807
8800
8808
format ( ) {
8801
8809
this . range = this . set
8802
- . map ( ( comps ) => {
8803
- return comps . join ( ' ' ) . trim ( )
8804
- } )
8810
+ . map ( ( comps ) => comps . join ( ' ' ) . trim ( ) )
8805
8811
. join ( '||' )
8806
8812
. trim ( )
8807
8813
return this . range
@@ -8812,8 +8818,6 @@ class Range {
8812
8818
}
8813
8819
8814
8820
parseRange ( range ) {
8815
- range = range . trim ( )
8816
-
8817
8821
// memoize range parsing for performance.
8818
8822
// this is a very hot path, and fully deterministic.
8819
8823
const memoOpts =
@@ -8840,9 +8844,6 @@ class Range {
8840
8844
// `^ 1.2.3` => `^1.2.3`
8841
8845
range = range . replace ( re [ t . CARETTRIM ] , caretTrimReplace )
8842
8846
8843
- // normalize spaces
8844
- range = range . split ( / \s + / ) . join ( ' ' )
8845
-
8846
8847
// At this point, the range is completely trimmed and
8847
8848
// ready to be split into comparators.
8848
8849
@@ -8938,7 +8939,7 @@ const Comparator = __nccwpck_require__(1532)
8938
8939
const debug = __nccwpck_require__ ( 427 )
8939
8940
const SemVer = __nccwpck_require__ ( 8088 )
8940
8941
const {
8941
- re,
8942
+ safeRe : re ,
8942
8943
t,
8943
8944
comparatorTrimReplace,
8944
8945
tildeTrimReplace,
@@ -8992,10 +8993,13 @@ const isX = id => !id || id.toLowerCase() === 'x' || id === '*'
8992
8993
// ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0-0
8993
8994
// ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0-0
8994
8995
// ~0.0.1 --> >=0.0.1 <0.1.0-0
8995
- const replaceTildes = ( comp , options ) =>
8996
- comp . trim ( ) . split ( / \s + / ) . map ( ( c ) => {
8997
- return replaceTilde ( c , options )
8998
- } ) . join ( ' ' )
8996
+ const replaceTildes = ( comp , options ) => {
8997
+ return comp
8998
+ . trim ( )
8999
+ . split ( / \s + / )
9000
+ . map ( ( c ) => replaceTilde ( c , options ) )
9001
+ . join ( ' ' )
9002
+ }
8999
9003
9000
9004
const replaceTilde = ( comp , options ) => {
9001
9005
const r = options . loose ? re [ t . TILDELOOSE ] : re [ t . TILDE ]
@@ -9033,10 +9037,13 @@ const replaceTilde = (comp, options) => {
9033
9037
// ^1.2.0 --> >=1.2.0 <2.0.0-0
9034
9038
// ^0.0.1 --> >=0.0.1 <0.0.2-0
9035
9039
// ^0.1.0 --> >=0.1.0 <0.2.0-0
9036
- const replaceCarets = ( comp , options ) =>
9037
- comp . trim ( ) . split ( / \s + / ) . map ( ( c ) => {
9038
- return replaceCaret ( c , options )
9039
- } ) . join ( ' ' )
9040
+ const replaceCarets = ( comp , options ) => {
9041
+ return comp
9042
+ . trim ( )
9043
+ . split ( / \s + / )
9044
+ . map ( ( c ) => replaceCaret ( c , options ) )
9045
+ . join ( ' ' )
9046
+ }
9040
9047
9041
9048
const replaceCaret = ( comp , options ) => {
9042
9049
debug ( 'caret' , comp , options )
@@ -9093,9 +9100,10 @@ const replaceCaret = (comp, options) => {
9093
9100
9094
9101
const replaceXRanges = ( comp , options ) => {
9095
9102
debug ( 'replaceXRanges' , comp , options )
9096
- return comp . split ( / \s + / ) . map ( ( c ) => {
9097
- return replaceXRange ( c , options )
9098
- } ) . join ( ' ' )
9103
+ return comp
9104
+ . split ( / \s + / )
9105
+ . map ( ( c ) => replaceXRange ( c , options ) )
9106
+ . join ( ' ' )
9099
9107
}
9100
9108
9101
9109
const replaceXRange = ( comp , options ) => {
@@ -9178,12 +9186,15 @@ const replaceXRange = (comp, options) => {
9178
9186
const replaceStars = ( comp , options ) => {
9179
9187
debug ( 'replaceStars' , comp , options )
9180
9188
// Looseness is ignored here. star is always as loose as it gets!
9181
- return comp . trim ( ) . replace ( re [ t . STAR ] , '' )
9189
+ return comp
9190
+ . trim ( )
9191
+ . replace ( re [ t . STAR ] , '' )
9182
9192
}
9183
9193
9184
9194
const replaceGTE0 = ( comp , options ) => {
9185
9195
debug ( 'replaceGTE0' , comp , options )
9186
- return comp . trim ( )
9196
+ return comp
9197
+ . trim ( )
9187
9198
. replace ( re [ options . includePrerelease ? t . GTE0PRE : t . GTE0 ] , '' )
9188
9199
}
9189
9200
@@ -9221,7 +9232,7 @@ const hyphenReplace = incPr => ($0,
9221
9232
to = `<=${ to } `
9222
9233
}
9223
9234
9224
- return ( `${ from } ${ to } ` ) . trim ( )
9235
+ return `${ from } ${ to } ` . trim ( )
9225
9236
}
9226
9237
9227
9238
const testSet = ( set , version , options ) => {
@@ -9268,7 +9279,7 @@ const testSet = (set, version, options) => {
9268
9279
9269
9280
const debug = __nccwpck_require__ ( 427 )
9270
9281
const { MAX_LENGTH , MAX_SAFE_INTEGER } = __nccwpck_require__ ( 2293 )
9271
- const { re, t } = __nccwpck_require__ ( 9523 )
9282
+ const { safeRe : re , t } = __nccwpck_require__ ( 9523 )
9272
9283
9273
9284
const parseOptions = __nccwpck_require__ ( 785 )
9274
9285
const { compareIdentifiers } = __nccwpck_require__ ( 2463 )
@@ -9559,8 +9570,10 @@ class SemVer {
9559
9570
default :
9560
9571
throw new Error ( `invalid increment argument: ${ release } ` )
9561
9572
}
9562
- this . format ( )
9563
- this . raw = this . version
9573
+ this . raw = this . format ( )
9574
+ if ( this . build . length ) {
9575
+ this . raw += `+${ this . build . join ( '.' ) } `
9576
+ }
9564
9577
return this
9565
9578
}
9566
9579
}
@@ -9647,7 +9660,7 @@ module.exports = cmp
9647
9660
9648
9661
const SemVer = __nccwpck_require__ ( 8088 )
9649
9662
const parse = __nccwpck_require__ ( 5925 )
9650
- const { re, t } = __nccwpck_require__ ( 9523 )
9663
+ const { safeRe : re , t } = __nccwpck_require__ ( 9523 )
9651
9664
9652
9665
const coerce = ( version , options ) => {
9653
9666
if ( version instanceof SemVer ) {
@@ -9755,6 +9768,35 @@ const diff = (version1, version2) => {
9755
9768
const highVersion = v1Higher ? v1 : v2
9756
9769
const lowVersion = v1Higher ? v2 : v1
9757
9770
const highHasPre = ! ! highVersion . prerelease . length
9771
+ const lowHasPre = ! ! lowVersion . prerelease . length
9772
+
9773
+ if ( lowHasPre && ! highHasPre ) {
9774
+ // Going from prerelease -> no prerelease requires some special casing
9775
+
9776
+ // If the low version has only a major, then it will always be a major
9777
+ // Some examples:
9778
+ // 1.0.0-1 -> 1.0.0
9779
+ // 1.0.0-1 -> 1.1.1
9780
+ // 1.0.0-1 -> 2.0.0
9781
+ if ( ! lowVersion . patch && ! lowVersion . minor ) {
9782
+ return 'major'
9783
+ }
9784
+
9785
+ // Otherwise it can be determined by checking the high version
9786
+
9787
+ if ( highVersion . patch ) {
9788
+ // anything higher than a patch bump would result in the wrong version
9789
+ return 'patch'
9790
+ }
9791
+
9792
+ if ( highVersion . minor ) {
9793
+ // anything higher than a minor bump would result in the wrong version
9794
+ return 'minor'
9795
+ }
9796
+
9797
+ // bumping major/minor/patch all have same result
9798
+ return 'major'
9799
+ }
9758
9800
9759
9801
// add the `pre` prefix if we are going to a prerelease version
9760
9802
const prefix = highHasPre ? 'pre' : ''
@@ -9771,26 +9813,8 @@ const diff = (version1, version2) => {
9771
9813
return prefix + 'patch'
9772
9814
}
9773
9815
9774
- // at this point we know stable versions match but overall versions are not equal,
9775
- // so either they are both prereleases, or the lower version is a prerelease
9776
-
9777
- if ( highHasPre ) {
9778
- // high and low are preleases
9779
- return 'prerelease'
9780
- }
9781
-
9782
- if ( lowVersion . patch ) {
9783
- // anything higher than a patch bump would result in the wrong version
9784
- return 'patch'
9785
- }
9786
-
9787
- if ( lowVersion . minor ) {
9788
- // anything higher than a minor bump would result in the wrong version
9789
- return 'minor'
9790
- }
9791
-
9792
- // bumping major/minor/patch all have same result
9793
- return 'major'
9816
+ // high and low are preleases
9817
+ return 'prerelease'
9794
9818
}
9795
9819
9796
9820
module . exports = diff
@@ -10220,16 +10244,27 @@ exports = module.exports = {}
10220
10244
10221
10245
// The actual regexps go on exports.re
10222
10246
const re = exports . re = [ ]
10247
+ const safeRe = exports . safeRe = [ ]
10223
10248
const src = exports . src = [ ]
10224
10249
const t = exports . t = { }
10225
10250
let R = 0
10226
10251
10227
10252
const createToken = ( name , value , isGlobal ) => {
10253
+ // Replace all greedy whitespace to prevent regex dos issues. These regex are
10254
+ // used internally via the safeRe object since all inputs in this library get
10255
+ // normalized first to trim and collapse all extra whitespace. The original
10256
+ // regexes are exported for userland consumption and lower level usage. A
10257
+ // future breaking change could export the safer regex only with a note that
10258
+ // all input should have extra whitespace removed.
10259
+ const safe = value
10260
+ . split ( '\\s*' ) . join ( '\\s{0,1}' )
10261
+ . split ( '\\s+' ) . join ( '\\s' )
10228
10262
const index = R ++
10229
10263
debug ( name , index , value )
10230
10264
t [ name ] = index
10231
10265
src [ index ] = value
10232
10266
re [ index ] = new RegExp ( value , isGlobal ? 'g' : undefined )
10267
+ safeRe [ index ] = new RegExp ( safe , isGlobal ? 'g' : undefined )
10233
10268
}
10234
10269
10235
10270
// The following Regular Expressions can be used for tokenizing,
0 commit comments