Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
})