Explicitely prohibit space and special character in theme names

This commit is contained in:
Joseph Garrone 2024-09-28 00:34:24 +02:00
parent 04307c8226
commit 802a6ab5ec

View File

@ -468,6 +468,7 @@ export function getBuildContext(params: {
process.exit(-1); process.exit(-1);
} }
const themeNames = ((): [string, ...string[]] => {
const themeNames = ((): [string, ...string[]] => { const themeNames = ((): [string, ...string[]] => {
if (buildOptions.themeName === undefined) { if (buildOptions.themeName === undefined) {
return parsedPackageJson.name === undefined return parsedPackageJson.name === undefined
@ -491,6 +492,23 @@ export function getBuildContext(params: {
return [mainThemeName, ...themeVariantNames]; 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);
}
}
return themeNames;
})();
const projectBuildDirPath = (() => { const projectBuildDirPath = (() => {
webpack: { webpack: {
if (bundler !== "webpack") { if (bundler !== "webpack") {