diff --git a/src/context/yaml/handlers/branding.ts b/src/context/yaml/handlers/branding.ts index 7260d883c..fb7c42f6f 100644 --- a/src/context/yaml/handlers/branding.ts +++ b/src/context/yaml/handlers/branding.ts @@ -6,6 +6,7 @@ import { YAMLHandler } from '.'; import YAMLContext from '..'; import { Asset, ParsedAsset } from '../../../types'; import log from '../../../logger'; +import { nomalizedYAMLPath } from '../../../utils'; type BrandingTemplate = { template: string; @@ -32,7 +33,7 @@ async function parse(context: YAMLContext): Promise { const parsedTemplates: BrandingTemplate[] = templates.map( (templateDefinition: BrandingTemplate): BrandingTemplate => { - const normalizedPathSplit = path.normalize(templateDefinition.body).split(path.sep); + const normalizedPathSplit = nomalizedYAMLPath(templateDefinition.body); const markupFile = path.join(context.basePath, ...normalizedPathSplit); return { template: templateDefinition.template, diff --git a/src/utils.ts b/src/utils.ts index 46e254242..97561159b 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -205,3 +205,29 @@ export function mapClientID2NameSorted(enabledClients: string[], knownClients: A ...(enabledClients || []).map((clientId) => convertClientIdToName(clientId, knownClients)), ].sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase())); } + +export function nomalizedYAMLPath(filePath: string): string[] { + // Trim any leading or trailing whitespace + filePath = filePath.trim(); + + // Handle empty path cases + if (filePath === '') { + return []; + } + + // Normalize the path by replacing backslashes with forward slashes + const normalizedPath = filePath.replace(/\\/g, '/'); + + // Split the path using the forward slash as the separator + let pathSplit = normalizedPath.split('/'); + + // Remove empty components resulting from leading or redundant slashes + pathSplit = pathSplit.filter(component => component !== ''); + + // Remove the first '.' if it's the first component + if (pathSplit.length > 0 && pathSplit[0] === '.') { + pathSplit.shift(); + } + + return pathSplit; +}