mirror of
https://github.com/agregarr/agregarr.git
synced 2026-05-08 11:50:17 -05:00
fix(posters): validate SVG icon dimensions and file type (#350)
Validates SVG dimensions before scale calculation to prevent division by zero. Warns when non-SVG files passed with hint about required format. Co-authored-by: bitr8 <bitr8@users.noreply.github.com>
This commit is contained in:
@@ -1302,6 +1302,11 @@ async function embedSVGIconInSVG(
|
||||
|
||||
// Only process SVG files in this function
|
||||
if (!filename.toLowerCase().endsWith('.svg')) {
|
||||
logger.warn('Icon is not an SVG file, cannot embed in poster', {
|
||||
iconPath,
|
||||
filename,
|
||||
hint: 'Custom icons must be SVG format for poster templates',
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1332,6 +1337,21 @@ async function embedSVGIconInSVG(
|
||||
if (heightMatch) svgHeight = parseFloat(heightMatch[1]);
|
||||
}
|
||||
|
||||
// Validate SVG dimensions - prevent division by zero or NaN
|
||||
if (
|
||||
!Number.isFinite(svgWidth) ||
|
||||
!Number.isFinite(svgHeight) ||
|
||||
svgWidth <= 0 ||
|
||||
svgHeight <= 0
|
||||
) {
|
||||
logger.warn('Invalid SVG dimensions, cannot embed icon', {
|
||||
iconPath,
|
||||
svgWidth,
|
||||
svgHeight,
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
// Calculate scale to fit the element dimensions while maintaining aspect ratio
|
||||
const scaleX = element.width / svgWidth;
|
||||
const scaleY = element.height / svgHeight;
|
||||
|
||||
Reference in New Issue
Block a user