Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions packages/core/image-asset/image-asset-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,26 @@ export function getAspectSafeDimensions(sourceWidth, sourceHeight, reqWidth, req
}

export function getRequestedImageSize(src: { width: number; height: number }, options: ImageAssetOptions): { width: number; height: number } {
let reqWidth = options.width || Math.min(src.width, Screen.mainScreen.widthPixels);
let reqHeight = options.height || Math.min(src.height, Screen.mainScreen.heightPixels);

if (options && options.keepAspectRatio) {
const safeAspectSize = getAspectSafeDimensions(src.width, src.height, reqWidth, reqHeight);
reqWidth = safeAspectSize.width;
reqHeight = safeAspectSize.height;
}
// Coerce width and height to numbers if they are strings
let reqWidth = options.width || Math.min(src.width, Screen.mainScreen.widthPixels);
let reqHeight = options.height || Math.min(src.height, Screen.mainScreen.heightPixels);

return {
width: reqWidth,
height: reqHeight,
};
if (typeof reqWidth === 'string') {
reqWidth = parseInt(reqWidth, 10);
}
if (typeof reqHeight === 'string') {
reqHeight = parseInt(reqHeight, 10);
Comment on lines +56 to +59
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ImageAssetOptions interface defines width and height as optional number types, but this code suggests they could be strings at runtime. Consider using Number() or adding explicit NaN validation after parseInt(), as parseInt() can return NaN for invalid strings, which would propagate through calculations.

Suggested change
reqWidth = parseInt(reqWidth, 10);
}
if (typeof reqHeight === 'string') {
reqHeight = parseInt(reqHeight, 10);
const parsedWidth = parseInt(reqWidth, 10);
reqWidth = isNaN(parsedWidth) ? Math.min(src.width, Screen.mainScreen.widthPixels) : parsedWidth;
}
if (typeof reqHeight === 'string') {
const parsedHeight = parseInt(reqHeight, 10);
reqHeight = isNaN(parsedHeight) ? Math.min(src.height, Screen.mainScreen.heightPixels) : parsedHeight;

Copilot uses AI. Check for mistakes.
}
Comment on lines +52 to +60
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The string coercion checks on lines 55-60 occur after using the fallback logic on lines 52-53. If options.width or options.height are strings, the || operator won't trigger the fallback because non-empty strings are truthy. The string type checks should occur before or be integrated with the fallback logic to ensure proper behavior.

Copilot uses AI. Check for mistakes.

if (options && options.keepAspectRatio) {
const safeAspectSize = getAspectSafeDimensions(src.width, src.height, reqWidth, reqHeight);
reqWidth = safeAspectSize.width;
reqHeight = safeAspectSize.height;
}

return {
width: reqWidth,
height: reqHeight,
};
}