From fa588a6444e611f9f697a4b07193bb3254a64216 Mon Sep 17 00:00:00 2001 From: Christian Vidal Wolf Date: Thu, 26 Feb 2026 10:37:50 +0100 Subject: [PATCH] fix(dataProcessor): improve regex parsing for week number in Ads and Traffic CSV/Excel import --- services/dataProcessor.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/services/dataProcessor.ts b/services/dataProcessor.ts index 78efb2a..43ef769 100644 --- a/services/dataProcessor.ts +++ b/services/dataProcessor.ts @@ -460,7 +460,8 @@ export const processAdsCSV = (file: File): Promise => { if (!asin || !countryRaw || weekRaw === undefined || weekRaw === '') continue; - const weekNum = parseInt(String(weekRaw)); + const weekMatch = String(weekRaw).match(/\d+/); + const weekNum = weekMatch ? parseInt(weekMatch[0], 10) : NaN; if (isNaN(weekNum) || weekNum < 1 || weekNum > 53) continue; // For CSV without sheet names, assume current year @@ -540,7 +541,8 @@ export const processAdsExcel = async (fileOrBuffer: File | ArrayBuffer): Promise // Skip if missing essential data if (!asin || !countryRaw || weekRaw === undefined || weekRaw === '') continue; - const weekNum = parseInt(String(weekRaw)); + const weekMatch = String(weekRaw).match(/\d+/); + const weekNum = weekMatch ? parseInt(weekMatch[0], 10) : NaN; if (isNaN(weekNum) || weekNum < 1 || weekNum > 53) continue; // Log first parsed row per sheet for column match diagnosis @@ -632,7 +634,8 @@ export const processTrafficExcel = async (fileOrBuffer: File | ArrayBuffer): Pro if (!asin || yearRaw === undefined || weekRaw === undefined || !countryRaw) continue; const year = typeof yearRaw === 'number' ? yearRaw : parseInt(String(yearRaw)); - const weekNum = parseInt(String(weekRaw)); + const weekMatch = String(weekRaw).match(/\d+/); + const weekNum = weekMatch ? parseInt(weekMatch[0], 10) : NaN; if (isNaN(year) || year < 2020 || year > 2100) continue; if (isNaN(weekNum) || weekNum < 1 || weekNum > 53) continue;