Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow . to prefix prerelease in loose mode #167

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions internal/re.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,13 @@ createToken('PRERELEASEIDENTIFIERLOOSE', `(?:${src[t.NUMERICIDENTIFIERLOOSE]
createToken('PRERELEASE', `(?:-(${src[t.PRERELEASEIDENTIFIER]
}(?:\\.${src[t.PRERELEASEIDENTIFIER]})*))`)

createToken('PRERELEASELOOSE', `(?:-?(${src[t.PRERELEASEIDENTIFIERLOOSE]
}(?:\\.${src[t.PRERELEASEIDENTIFIERLOOSE]})*))`)
// loose mode prereleases can start with a dot, but only if they're not numeric
// 1.2.3.foo is allowed, 1.2.3.4 is not.
createToken('PRERELEASELOOSE', `(?:(?:-|\\.*(?=[a-zA-Z-]))(${
src[t.PRERELEASEIDENTIFIERLOOSE]
}(?:\\.${
src[t.PRERELEASEIDENTIFIERLOOSE]
})*))`)

// ## Build Metadata Identifier
// Any combination of digits, letters, or hyphens.
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/invalid-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ module.exports = [
[/a regexp/, 'regexp is not a string'],
[/1.2.3/, 'semver-ish regexp is not a string'],
[{ toString: () => '1.2.3' }, 'obj with a tostring is not a string'],
['1.2.3.foo', 'no dot-led prerelease tag, strict'],
['1.2.3.4', 'no dot-led numeric prerelease tag, strict'],
['1.2.3.4', 'no dot-led numeric prerelease tag, loose', { loose: true }],
]
4 changes: 4 additions & 0 deletions test/functions/valid.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@ t.test('validate a version into a SemVer object', t => {
t.equal(valid(s), '4.5.6', 'return the version if a SemVer obj')
t.equal(valid('4.2.0foo', true), '4.2.0-foo', 'looseness as a boolean')
t.equal(valid('4.2.0foo', { loose: true }), '4.2.0-foo', 'looseness as an option')
t.equal(valid('4.2.0.foo', { loose: true }), '4.2.0-foo', '.pre allowed in loose mode')
t.equal(valid('4.2.0.-foo', { loose: true }), '4.2.0--foo', '.-pre allowed in loose mode')
t.equal(valid('4.2.0--foo', { loose: true }), '4.2.0--foo', '--pre allowed in loose mode')
t.equal(valid('4.2.0--foo'), '4.2.0--foo', 'double-dash, strict')
t.end()
})