Unverified Commit 3e449b23 authored by Fellipe Utaka's avatar Fellipe Utaka Committed by GitHub

fix(create-next-app): validate --import-alias value (#63855)

Fixes #63854

Previously, there was no check when a path was passed with the
--import-alias flag. Furthermore, the regex used before did not check
for possible invalid paths.

The current regex checks the following conditions:
- It must follow the pattern `<prefix>/*`
- The prefix cannot contain invalid characters for folders, such as:
(whitespaces, /, <, >, :, ", /, \, |, ? and *)

---------
Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
parent 53d017d3
...@@ -381,9 +381,10 @@ async function run(): Promise<void> { ...@@ -381,9 +381,10 @@ async function run(): Promise<void> {
} }
} }
const importAliasPattern = /^[^*"]+\/\*\s*$/
if ( if (
typeof program.importAlias !== 'string' || typeof program.importAlias !== 'string' ||
!program.importAlias.length !importAliasPattern.test(program.importAlias)
) { ) {
if (ciInfo.isCI) { if (ciInfo.isCI) {
// We don't use preferences here because the default value is @/* regardless of existing preferences // We don't use preferences here because the default value is @/* regardless of existing preferences
...@@ -414,7 +415,7 @@ async function run(): Promise<void> { ...@@ -414,7 +415,7 @@ async function run(): Promise<void> {
message: `What ${styledImportAlias} would you like configured?`, message: `What ${styledImportAlias} would you like configured?`,
initial: getPrefOrDefault('importAlias'), initial: getPrefOrDefault('importAlias'),
validate: (value) => validate: (value) =>
/.+\/\*/.test(value) importAliasPattern.test(value)
? true ? true
: 'Import alias must follow the pattern <prefix>/*', : 'Import alias must follow the pattern <prefix>/*',
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment