From 802a6ab5ecd653f6d058887d4e896f7e375460fd Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Sat, 28 Sep 2024 00:34:24 +0200 Subject: [PATCH] Explicitely prohibit space and special character in theme names --- src/bin/shared/buildContext.ts | 54 ++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/src/bin/shared/buildContext.ts b/src/bin/shared/buildContext.ts index ea5aa510..b4a998b7 100644 --- a/src/bin/shared/buildContext.ts +++ b/src/bin/shared/buildContext.ts @@ -469,26 +469,44 @@ export function getBuildContext(params: { } const themeNames = ((): [string, ...string[]] => { - if (buildOptions.themeName === undefined) { - return parsedPackageJson.name === undefined - ? ["keycloakify"] - : [ - parsedPackageJson.name - .replace(/^@(.*)/, "$1") - .split("/") - .join("-") - ]; + const themeNames = ((): [string, ...string[]] => { + if (buildOptions.themeName === undefined) { + return parsedPackageJson.name === undefined + ? ["keycloakify"] + : [ + parsedPackageJson.name + .replace(/^@(.*)/, "$1") + .split("/") + .join("-") + ]; + } + + if (typeof buildOptions.themeName === "string") { + return [buildOptions.themeName]; + } + + const [mainThemeName, ...themeVariantNames] = buildOptions.themeName; + + assert(mainThemeName !== undefined); + + return [mainThemeName, ...themeVariantNames]; + })(); + + for (const themeName of themeNames) { + if (!/^[a-zA-Z0-9_-]+$/.test(themeName)) { + console.error( + chalk.red( + [ + `Invalid theme name: ${themeName}`, + `Theme names should only contain letters, numbers, and "_" or "-"` + ].join(" ") + ) + ); + process.exit(-1); + } } - if (typeof buildOptions.themeName === "string") { - return [buildOptions.themeName]; - } - - const [mainThemeName, ...themeVariantNames] = buildOptions.themeName; - - assert(mainThemeName !== undefined); - - return [mainThemeName, ...themeVariantNames]; + return themeNames; })(); const projectBuildDirPath = (() => {