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> {
}
}
const importAliasPattern = /^[^*"]+\/\*\s*$/
if (
typeof program.importAlias !== 'string' ||
!program.importAlias.length
!importAliasPattern.test(program.importAlias)
) {
if (ciInfo.isCI) {
// We don't use preferences here because the default value is @/* regardless of existing preferences
......@@ -414,7 +415,7 @@ async function run(): Promise<void> {
message: `What ${styledImportAlias} would you like configured?`,
initial: getPrefOrDefault('importAlias'),
validate: (value) =>
/.+\/\*/.test(value)
importAliasPattern.test(value)
? true
: '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