Skip to content

Commit 1180a53

Browse files
committed
fix: adding validation for scoped packages that begin with one or more periods
1 parent c45bc37 commit 1180a53

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ function validate (name) {
3030
errors.push('name length must be greater than zero')
3131
}
3232

33-
if (name.match(/^\./)) {
33+
// cannot start with period, both scoped and unscoped
34+
if (name.match(/^\./) || name.match(/^(?:@([^/]+?)[/])?(\.[^/]*)$/)) {
3435
errors.push('name cannot start with a period')
3536
}
3637

test/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,21 @@ test('validate-npm-package-name', function (t) {
5353
validForOldPackages: false,
5454
errors: ['name cannot start with a period'] })
5555

56+
t.same(validate('@npm/.'), {
57+
validForNewPackages: false,
58+
validForOldPackages: false,
59+
errors: ['name cannot start with a period'] })
60+
61+
t.same(validate('@npm/..'), {
62+
validForNewPackages: false,
63+
validForOldPackages: false,
64+
errors: ['name cannot start with a period'] })
65+
66+
t.same(validate('@npm/.package'), {
67+
validForNewPackages: false,
68+
validForOldPackages: false,
69+
errors: ['name cannot start with a period'] })
70+
5671
t.same(validate('_start-with-underscore'), {
5772
validForNewPackages: false,
5873
validForOldPackages: false,

0 commit comments

Comments
 (0)