Skip to content

Commit

Permalink
fix: prevent adding invalid dist-tag
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar committed Feb 1, 2024
1 parent 5b7184f commit c163785
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/commands/dist-tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ class DistTag extends BaseCommand {

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

// make sure new spec with tag is valid, this will throw if invalid
npa(`${spec.name}@${defaultTag}`)

if (!spec.name || !version || !defaultTag) {
throw this.usageError('must provide a spec with a name and version, and a tag to add')
}
Expand Down
9 changes: 9 additions & 0 deletions test/lib/commands/dist-tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,15 @@ t.test('add missing pkg name', async t => {
)
})

t.test('add invalid tag', async t => {
const { distTag } = await mockDist(t)
await t.rejects(
distTag.exec(['add', '@tag']),
{ code: 'EINVALIDTAGNAME'},

Check failure on line 325 in test/lib/commands/dist-tag.js

View workflow job for this annotation

GitHub Actions / Lint

A space is required before '}'
'should exit with invalida tag name error'
)
})

t.test('set existing version', async t => {
const { distTag, logs } = await mockDist(t)
await distTag.exec(['set', '@scoped/another@0.6.0', 'b'])
Expand Down

0 comments on commit c163785

Please sign in to comment.