Skip to content

Commit b0a3ba0

Browse files
authored
fix: prevent adding invalid dist-tag (#7195)
1 parent 5b7184f commit b0a3ba0

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/commands/dist-tag.js

+3
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ class DistTag extends BaseCommand {
8989

9090
log.verbose('dist-tag add', defaultTag, 'to', spec.name + '@' + version)
9191

92+
// make sure new spec with tag is valid, this will throw if invalid
93+
npa(`${spec.name}@${defaultTag}`)
94+
9295
if (!spec.name || !version || !defaultTag) {
9396
throw this.usageError('must provide a spec with a name and version, and a tag to add')
9497
}

test/lib/commands/dist-tag.js

+9
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,15 @@ t.test('add missing pkg name', async t => {
318318
)
319319
})
320320

321+
t.test('add invalid tag', async t => {
322+
const { distTag } = await mockDist(t)
323+
await t.rejects(
324+
distTag.exec(['add', '@tag']),
325+
{ code: 'EINVALIDTAGNAME' },
326+
'should exit with invalid tag name error'
327+
)
328+
})
329+
321330
t.test('set existing version', async t => {
322331
const { distTag, logs } = await mockDist(t)
323332
await distTag.exec(['set', '@scoped/another@0.6.0', 'b'])

0 commit comments

Comments
 (0)