Skip to content

Commit 4ab6cf4

Browse files
authoredMay 1, 2024··
fix(publish): validate dist-tag (#7459)
1 parent f6fff32 commit 4ab6cf4

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed
 

‎lib/commands/publish.js

+4
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ class Publish extends BaseCommand {
9696
}
9797

9898
const resolved = npa.resolve(manifest.name, manifest.version)
99+
100+
// make sure tag is valid, this will throw if invalid
101+
npa(`${manifest.name}@${defaultTag}`)
102+
99103
const registry = npmFetch.pickRegistry(resolved, opts)
100104
const creds = this.npm.config.getCredentialsByURI(registry)
101105
const noCreds = !(creds.token || creds.username || creds.certfile && creds.keyfile)

‎test/lib/commands/publish.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ t.test('shows usage with wrong set of arguments', async t => {
291291
await t.rejects(publish.exec(['a', 'b', 'c']), publish.usage)
292292
})
293293

294-
t.test('throws when invalid tag', async t => {
294+
t.test('throws when invalid tag is semver', async t => {
295295
const { npm } = await loadMockNpm(t, {
296296
config: {
297297
tag: '0.0.13',
@@ -306,6 +306,24 @@ t.test('throws when invalid tag', async t => {
306306
)
307307
})
308308

309+
t.test('throws when invalid tag when not url encodable', async t => {
310+
const { npm } = await loadMockNpm(t, {
311+
config: {
312+
tag: '@test',
313+
},
314+
prefixDir: {
315+
'package.json': JSON.stringify(pkgJson, null, 2),
316+
},
317+
})
318+
await t.rejects(
319+
npm.exec('publish', []),
320+
{
321+
/* eslint-disable-next-line max-len */
322+
message: 'Invalid tag name "@test" of package "test-package@@test": Tags may not have any characters that encodeURIComponent encodes.',
323+
}
324+
)
325+
})
326+
309327
t.test('tarball', async t => {
310328
const { npm, joinedOutput, logs, home } = await loadMockNpm(t, {
311329
config: {

0 commit comments

Comments
 (0)
Please sign in to comment.