fix(parser): add alphanumeric sanitizer to excel header mapping to support characters like % and parenthesis

This commit is contained in:
Christian Vidal Wolf
2026-02-25 14:22:58 +01:00
parent 487b8e105e
commit 13dd4b62c2
+6 -2
View File
@@ -239,12 +239,16 @@ const normalizeMonth = (rawMonth: string): string => {
const getColumnValue = (row: any, aliases: string[]): string => { const getColumnValue = (row: any, aliases: string[]): string => {
const rowKeys = Object.keys(row); const rowKeys = Object.keys(row);
const normalizedRowKeys: Record<string, string> = {}; const normalizedRowKeys: Record<string, string> = {};
rowKeys.forEach(k => { rowKeys.forEach(k => {
normalizedRowKeys[k.trim().toLowerCase()] = k; // Normalize by removing all non-alphanumeric characters for a bulletproof exact match
// e.g., "ACOS %" -> "acos", "Sales (30d)" -> "sales30d"
const cleanKey = k.toLowerCase().replace(/[^a-z0-9]/g, '');
normalizedRowKeys[cleanKey] = k;
}); });
for (const alias of aliases) { for (const alias of aliases) {
const lookup = alias.trim().toLowerCase(); const lookup = alias.toLowerCase().replace(/[^a-z0-9]/g, '');
if (normalizedRowKeys[lookup]) { if (normalizedRowKeys[lookup]) {
const actualKey = normalizedRowKeys[lookup]; const actualKey = normalizedRowKeys[lookup];
const val = row[actualKey]; const val = row[actualKey];