Skip to content

Commit c5b2b75

Browse files
fix: use shared sanitizeFont in generateMonthlySVG and generateAutoThemeMonthlySVG (JhaSourav07#907)
* fix: use shared sanitizeFont in generateMonthlySVG and generateAutoThemeMonthlySVG - Both functions defined a local sanitizeFont that stripped single quotes - This shadowed the imported sanitizeFont from lib/svg/sanitizer.ts - Replace both local definitions with the shared imported function - Ensures consistent font sanitization across all badge views * fix: resolve FONT_MAP string index type error in generateMonthlySVG functions
1 parent 750bee0 commit c5b2b75

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

lib/svg/generator.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -489,9 +489,10 @@ export function generateMonthlySVG(stats: MonthlyStats, params: BadgeParams): st
489489
const accent = `#${sanitizeHexColor(params.accent, '00ffaa')}`;
490490
const text = `#${sanitizeHexColor(params.text, 'ffffff')}`;
491491

492-
const sanitizeFont = (name: string) => name.replace(/[^a-zA-Z0-9\s-]/g, '').trim();
493-
const sanitizedFont = params.font ? sanitizeFont(params.font) : null;
494-
const predefinedFont = getFontFromMap(sanitizedFont);
492+
const sanitizedFont = sanitizeFont(params.font);
493+
const predefinedFont = sanitizedFont
494+
? (FONT_MAP[sanitizedFont.toLowerCase() as keyof typeof FONT_MAP] ?? null)
495+
: null;
495496
const isPredefinedFont = Boolean(predefinedFont);
496497
const selectedFont = isPredefinedFont
497498
? predefinedFont
@@ -586,9 +587,10 @@ function generateAutoThemeMonthlySVG(stats: MonthlyStats, params: BadgeParams):
586587
const light = AUTO_THEME_LIGHT;
587588
const dark = AUTO_THEME_DARK;
588589
const safeUser = escapeXML(params.user || 'GitHub User');
589-
const sanitizeFont = (name: string) => name.replace(/[^a-zA-Z0-9\s-]/g, '').trim();
590-
const sanitizedFont = params.font ? sanitizeFont(params.font) : null;
591-
const predefinedFont = getFontFromMap(sanitizedFont);
590+
const sanitizedFont = sanitizeFont(params.font);
591+
const predefinedFont = sanitizedFont
592+
? (FONT_MAP[sanitizedFont.toLowerCase() as keyof typeof FONT_MAP] ?? null)
593+
: null;
592594
const isPredefinedFont = Boolean(predefinedFont);
593595
const selectedFont = isPredefinedFont
594596
? predefinedFont

0 commit comments

Comments
 (0)