Skip to content

Commit a6d75b5

Browse files
committed
fix(tag): add tag name validation (#19)
1 parent 2289c44 commit a6d75b5

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

src/commands/tag.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,31 @@ export function tagCommand(program: Command): void {
4747

4848
const trimmedTagname = tagname.trim();
4949

50+
if (trimmedTagname.length > 128) {
51+
console.error(chalk.red('❌ Error: Tag name must be 128 characters or less'));
52+
process.exit(1);
53+
}
54+
55+
if (!/^[a-zA-Z0-9._-]+$/.test(trimmedTagname)) {
56+
console.error(chalk.red('❌ Error: Tag name can only contain letters, numbers, dots, hyphens, and underscores'));
57+
process.exit(1);
58+
}
59+
60+
if (trimmedTagname === 'latest') {
61+
const { confirmLatest } = await inquirer.prompt([
62+
{
63+
type: 'confirm',
64+
name: 'confirmLatest',
65+
message: '"latest" is the default tag name used by envx. Are you sure you want to use it?',
66+
default: false,
67+
},
68+
]);
69+
if (!confirmLatest) {
70+
console.log(chalk.yellow('❌ Tag creation cancelled'));
71+
return;
72+
}
73+
}
74+
5075
// 检查标签是否已存在(通过尝试读取该 tag 的 envs)
5176
const existingTagEnvs = await getEnvs(configPath, trimmedTagname);
5277
if (Object.keys(existingTagEnvs).length > 0) {

0 commit comments

Comments
 (0)