Skip to content

Commit 99d8287

Browse files
authoredJul 7, 2023
fix: correctly parse long build ids as valid (#583)
Fixes #580
1 parent 4f0f6b1 commit 99d8287

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed
 

‎internal/re.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
const { MAX_SAFE_COMPONENT_LENGTH, MAX_SAFE_BUILD_LENGTH } = require('./constants')
1+
const {
2+
MAX_SAFE_COMPONENT_LENGTH,
3+
MAX_SAFE_BUILD_LENGTH,
4+
MAX_LENGTH,
5+
} = require('./constants')
26
const debug = require('./debug')
37
exports = module.exports = {}
48

@@ -19,7 +23,7 @@ const LETTERDASHNUMBER = '[a-zA-Z0-9-]'
1923
// all input should have extra whitespace removed.
2024
const safeRegexReplacements = [
2125
['\\s', 1],
22-
['\\d', MAX_SAFE_COMPONENT_LENGTH],
26+
['\\d', MAX_LENGTH],
2327
[LETTERDASHNUMBER, MAX_SAFE_BUILD_LENGTH],
2428
]
2529

‎test/functions/valid.js

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const t = require('tap')
22
const valid = require('../../functions/valid')
33
const SemVer = require('../../classes/semver')
44
const invalidVersions = require('../fixtures/invalid-versions')
5+
const { MAX_SAFE_INTEGER } = require('../../internal/constants')
56

67
t.test('returns null instead of throwing when presented with garbage', t => {
78
t.plan(invalidVersions.length)
@@ -17,3 +18,12 @@ t.test('validate a version into a SemVer object', t => {
1718
t.equal(valid('4.2.0foo', { loose: true }), '4.2.0-foo', 'looseness as an option')
1819
t.end()
1920
})
21+
22+
t.test('long build id', t => {
23+
const longBuild = '-928490632884417731e7af463c92b034d6a78268fc993bcb88a57944'
24+
const shortVersion = '1.1.1'
25+
const longVersion = `${MAX_SAFE_INTEGER}.${MAX_SAFE_INTEGER}.${MAX_SAFE_INTEGER}`
26+
t.equal(valid(shortVersion + longBuild), shortVersion + longBuild)
27+
t.equal(valid(longVersion + longBuild), longVersion + longBuild)
28+
t.end()
29+
})

0 commit comments

Comments
 (0)
Please sign in to comment.