Skip to content

Commit

Permalink
fix: correctly parse long build ids as valid (npm#583)
Browse files Browse the repository at this point in the history
Fixes npm#580
  • Loading branch information
lukekarrys authored Jul 7, 2023
1 parent 4f0f6b1 commit 99d8287
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
8 changes: 6 additions & 2 deletions internal/re.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
const { MAX_SAFE_COMPONENT_LENGTH, MAX_SAFE_BUILD_LENGTH } = require('./constants')
const {
MAX_SAFE_COMPONENT_LENGTH,
MAX_SAFE_BUILD_LENGTH,
MAX_LENGTH,
} = require('./constants')
const debug = require('./debug')
exports = module.exports = {}

Expand All @@ -19,7 +23,7 @@ const LETTERDASHNUMBER = '[a-zA-Z0-9-]'
// all input should have extra whitespace removed.
const safeRegexReplacements = [
['\\s', 1],
['\\d', MAX_SAFE_COMPONENT_LENGTH],
['\\d', MAX_LENGTH],
[LETTERDASHNUMBER, MAX_SAFE_BUILD_LENGTH],
]

Expand Down
10 changes: 10 additions & 0 deletions test/functions/valid.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const t = require('tap')
const valid = require('../../functions/valid')
const SemVer = require('../../classes/semver')
const invalidVersions = require('../fixtures/invalid-versions')
const { MAX_SAFE_INTEGER } = require('../../internal/constants')

t.test('returns null instead of throwing when presented with garbage', t => {
t.plan(invalidVersions.length)
Expand All @@ -17,3 +18,12 @@ t.test('validate a version into a SemVer object', t => {
t.equal(valid('4.2.0foo', { loose: true }), '4.2.0-foo', 'looseness as an option')
t.end()
})

t.test('long build id', t => {
const longBuild = '-928490632884417731e7af463c92b034d6a78268fc993bcb88a57944'
const shortVersion = '1.1.1'
const longVersion = `${MAX_SAFE_INTEGER}.${MAX_SAFE_INTEGER}.${MAX_SAFE_INTEGER}`
t.equal(valid(shortVersion + longBuild), shortVersion + longBuild)
t.equal(valid(longVersion + longBuild), longVersion + longBuild)
t.end()
})

0 comments on commit 99d8287

Please sign in to comment.