Skip to content

Commit 68a5c0e

Browse files
shmamwraithgar
authored andcommitted
fix: adding validation for scoped packages that begin with one or more periods
1 parent c45bc37 commit 68a5c0e

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/index.js

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

33-
if (name.match(/^\./)) {
33+
if (name.startsWith('.')) {
3434
errors.push('name cannot start with a period')
3535
}
3636

@@ -75,6 +75,11 @@ function validate (name) {
7575
if (nameMatch) {
7676
var user = nameMatch[1]
7777
var pkg = nameMatch[2]
78+
79+
if (pkg.startsWith('.')) {
80+
errors.push('name cannot start with a period')
81+
}
82+
7883
if (encodeURIComponent(user) === user && encodeURIComponent(pkg) === pkg) {
7984
return done(warnings, errors)
8085
}

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)