semver 7.5.2 → 7.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -159,7 +159,9 @@ of primitive `operators` is:
159
159
 
160
160
  For example, the comparator `>=1.2.7` would match the versions
161
161
  `1.2.7`, `1.2.8`, `2.5.3`, and `1.3.9`, but not the versions `1.2.6`
162
- or `1.1.0`.
162
+ or `1.1.0`. The comparator `>1` is equivalent to `>=2.0.0` and
163
+ would match the versions `2.0.0` and `3.1.0`, but not the versions
164
+ `1.0.1` or `1.1.0`.
163
165
 
164
166
  Comparators can be joined by whitespace to form a `comparator set`,
165
167
  which is satisfied by the **intersection** of all of the comparators
package/classes/range.js CHANGED
@@ -38,7 +38,7 @@ class Range {
38
38
  this.set = this.raw
39
39
  .split('||')
40
40
  // map the range to a 2d array of comparators
41
- .map(r => this.parseRange(r))
41
+ .map(r => this.parseRange(r.trim()))
42
42
  // throw out any comparator lists that are empty
43
43
  // this generally means that it was not a valid range, which is allowed
44
44
  // in loose mode, but will still throw if the WHOLE range is invalid.
@@ -98,15 +98,18 @@ class Range {
98
98
  const hr = loose ? re[t.HYPHENRANGELOOSE] : re[t.HYPHENRANGE]
99
99
  range = range.replace(hr, hyphenReplace(this.options.includePrerelease))
100
100
  debug('hyphen replace', range)
101
+
101
102
  // `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
102
103
  range = range.replace(re[t.COMPARATORTRIM], comparatorTrimReplace)
103
104
  debug('comparator trim', range)
104
105
 
105
106
  // `~ 1.2.3` => `~1.2.3`
106
107
  range = range.replace(re[t.TILDETRIM], tildeTrimReplace)
108
+ debug('tilde trim', range)
107
109
 
108
110
  // `^ 1.2.3` => `^1.2.3`
109
111
  range = range.replace(re[t.CARETTRIM], caretTrimReplace)
112
+ debug('caret trim', range)
110
113
 
111
114
  // At this point, the range is completely trimmed and
112
115
  // ready to be split into comparators.
@@ -9,6 +9,10 @@ const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER ||
9
9
  // Max safe segment length for coercion.
10
10
  const MAX_SAFE_COMPONENT_LENGTH = 16
11
11
 
12
+ // Max safe length for a build identifier. The max length minus 6 characters for
13
+ // the shortest version with a build 0.0.0+BUILD.
14
+ const MAX_SAFE_BUILD_LENGTH = MAX_LENGTH - 6
15
+
12
16
  const RELEASE_TYPES = [
13
17
  'major',
14
18
  'premajor',
@@ -22,6 +26,7 @@ const RELEASE_TYPES = [
22
26
  module.exports = {
23
27
  MAX_LENGTH,
24
28
  MAX_SAFE_COMPONENT_LENGTH,
29
+ MAX_SAFE_BUILD_LENGTH,
25
30
  MAX_SAFE_INTEGER,
26
31
  RELEASE_TYPES,
27
32
  SEMVER_SPEC_VERSION,
package/internal/re.js CHANGED
@@ -1,4 +1,8 @@
1
- const { MAX_SAFE_COMPONENT_LENGTH } = require('./constants')
1
+ const {
2
+ MAX_SAFE_COMPONENT_LENGTH,
3
+ MAX_SAFE_BUILD_LENGTH,
4
+ MAX_LENGTH,
5
+ } = require('./constants')
2
6
  const debug = require('./debug')
3
7
  exports = module.exports = {}
4
8
 
@@ -9,16 +13,31 @@ const src = exports.src = []
9
13
  const t = exports.t = {}
10
14
  let R = 0
11
15
 
16
+ const LETTERDASHNUMBER = '[a-zA-Z0-9-]'
17
+
18
+ // Replace some greedy regex tokens to prevent regex dos issues. These regex are
19
+ // used internally via the safeRe object since all inputs in this library get
20
+ // normalized first to trim and collapse all extra whitespace. The original
21
+ // regexes are exported for userland consumption and lower level usage. A
22
+ // future breaking change could export the safer regex only with a note that
23
+ // all input should have extra whitespace removed.
24
+ const safeRegexReplacements = [
25
+ ['\\s', 1],
26
+ ['\\d', MAX_LENGTH],
27
+ [LETTERDASHNUMBER, MAX_SAFE_BUILD_LENGTH],
28
+ ]
29
+
30
+ const makeSafeRegex = (value) => {
31
+ for (const [token, max] of safeRegexReplacements) {
32
+ value = value
33
+ .split(`${token}*`).join(`${token}{0,${max}}`)
34
+ .split(`${token}+`).join(`${token}{1,${max}}`)
35
+ }
36
+ return value
37
+ }
38
+
12
39
  const createToken = (name, value, isGlobal) => {
13
- // Replace all greedy whitespace to prevent regex dos issues. These regex are
14
- // used internally via the safeRe object since all inputs in this library get
15
- // normalized first to trim and collapse all extra whitespace. The original
16
- // regexes are exported for userland consumption and lower level usage. A
17
- // future breaking change could export the safer regex only with a note that
18
- // all input should have extra whitespace removed.
19
- const safe = value
20
- .split('\\s*').join('\\s{0,1}')
21
- .split('\\s+').join('\\s')
40
+ const safe = makeSafeRegex(value)
22
41
  const index = R++
23
42
  debug(name, index, value)
24
43
  t[name] = index
@@ -34,13 +53,13 @@ const createToken = (name, value, isGlobal) => {
34
53
  // A single `0`, or a non-zero digit followed by zero or more digits.
35
54
 
36
55
  createToken('NUMERICIDENTIFIER', '0|[1-9]\\d*')
37
- createToken('NUMERICIDENTIFIERLOOSE', '[0-9]+')
56
+ createToken('NUMERICIDENTIFIERLOOSE', '\\d+')
38
57
 
39
58
  // ## Non-numeric Identifier
40
59
  // Zero or more digits, followed by a letter or hyphen, and then zero or
41
60
  // more letters, digits, or hyphens.
42
61
 
43
- createToken('NONNUMERICIDENTIFIER', '\\d*[a-zA-Z-][a-zA-Z0-9-]*')
62
+ createToken('NONNUMERICIDENTIFIER', `\\d*[a-zA-Z-]${LETTERDASHNUMBER}*`)
44
63
 
45
64
  // ## Main Version
46
65
  // Three dot-separated numeric identifiers.
@@ -75,7 +94,7 @@ createToken('PRERELEASELOOSE', `(?:-?(${src[t.PRERELEASEIDENTIFIERLOOSE]
75
94
  // ## Build Metadata Identifier
76
95
  // Any combination of digits, letters, or hyphens.
77
96
 
78
- createToken('BUILDIDENTIFIER', '[0-9A-Za-z-]+')
97
+ createToken('BUILDIDENTIFIER', `${LETTERDASHNUMBER}+`)
79
98
 
80
99
  // ## Build Metadata
81
100
  // Plus sign, followed by one or more period-separated build metadata
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "semver",
3
- "version": "7.5.2",
3
+ "version": "7.5.4",
4
4
  "description": "The semantic version parser used by npm.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -14,7 +14,7 @@
14
14
  },
15
15
  "devDependencies": {
16
16
  "@npmcli/eslint-config": "^4.0.0",
17
- "@npmcli/template-oss": "4.15.1",
17
+ "@npmcli/template-oss": "4.17.0",
18
18
  "tap": "^16.0.0"
19
19
  },
20
20
  "license": "ISC",
@@ -53,7 +53,7 @@
53
53
  "author": "GitHub Inc.",
54
54
  "templateOSS": {
55
55
  "//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
56
- "version": "4.15.1",
56
+ "version": "4.17.0",
57
57
  "engines": ">=10",
58
58
  "ciVersions": [
59
59
  "10.0.0",