Skip to content

Commit ef9e768

Browse files
authored
Merge pull request #1 from Cff01/npmGH-164
Let '.' start non-numeric prerelease in loose mode
2 parents cb1ca1d + 174477e commit ef9e768

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

internal/re.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,13 @@ createToken('PRERELEASEIDENTIFIERLOOSE', `(?:${src[t.NUMERICIDENTIFIERLOOSE]
5858
createToken('PRERELEASE', `(?:-(${src[t.PRERELEASEIDENTIFIER]
5959
}(?:\\.${src[t.PRERELEASEIDENTIFIER]})*))`)
6060

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

6469
// ## Build Metadata Identifier
6570
// Any combination of digits, letters, or hyphens.

test/fixtures/invalid-versions.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ module.exports = [
1212
[ /a regexp/, 'regexp is not a string'],
1313
[ /1.2.3/, 'semver-ish regexp is not a string'],
1414
[ {toString: () => '1.2.3'}, 'obj with a tostring is not a string'],
15+
[ '1.2.3.foo', 'no dot-led prerelease tag, strict'],
16+
[ '1.2.3.4', 'no dot-led numeric prerelease tag, strict'],
17+
[ '1.2.3.4', 'no dot-led numeric prerelease tag, loose', { loose: true }],
1518
]

test/functions/valid.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,9 @@ t.test('validate a version into a SemVer object', t => {
1515
t.equal(valid(s), '4.5.6', 'return the version if a SemVer obj')
1616
t.equal(valid('4.2.0foo', true), '4.2.0-foo', 'looseness as a boolean')
1717
t.equal(valid('4.2.0foo', { loose: true }), '4.2.0-foo', 'looseness as an option')
18+
t.equal(valid('4.2.0.foo', { loose: true }), '4.2.0-foo', 'dot-led prerelease allowed in loose mode')
19+
t.equal(valid('4.2.0.-foo', { loose: true }), '4.2.0--foo', 'dot-and-dash-led prerelease allowed in loose mode')
20+
t.equal(valid('4.2.0--foo', { loose: true }), '4.2.0--foo', 'double-dash, loose')
21+
t.equal(valid('4.2.0--foo'), '4.2.0--foo', 'double-dash, strict')
1822
t.end()
1923
})

0 commit comments

Comments
 (0)