From 486014cea8a9edd7e525fccdd24323d2c0ab399a Mon Sep 17 00:00:00 2001 From: Calvin Sun Date: Fri, 5 Mar 2021 15:15:19 +0800 Subject: [PATCH] fix: #2360. Add validation for project name. --- packages/create-app/index.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/create-app/index.js b/packages/create-app/index.js index 489c7f02ace65b..18bd744e0b96cf 100755 --- a/packages/create-app/index.js +++ b/packages/create-app/index.js @@ -31,6 +31,7 @@ const TEMPLATES = [ const renameFiles = { _gitignore: '.gitignore' } +const projectNameRE = /^[A-Za-z0-9_-]*$/ async function init() { let targetDir = argv._[0] @@ -44,6 +45,12 @@ async function init() { message: `Project name:`, initial: 'vite-project' }) + if (!projectNameRE.test(name)) { + console.error( + `Project name "${name}" should only contain letters, numbers, underscores and dashs.` + ) + process.exit(1) + } targetDir = name }