From 5a706659c40198ad5c7c6eb8042408caed0195cc Mon Sep 17 00:00:00 2001 From: Christoph Nagel Date: Fri, 23 Aug 2024 14:25:12 +0200 Subject: [PATCH] 62: Adds range check for crop percentage values --- .../dam/impl/weboptimized/RelativeCroppingString.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/wcm/handler/mediasource/dam/impl/weboptimized/RelativeCroppingString.java b/src/main/java/io/wcm/handler/mediasource/dam/impl/weboptimized/RelativeCroppingString.java index 70aa67e4..a3a92d44 100644 --- a/src/main/java/io/wcm/handler/mediasource/dam/impl/weboptimized/RelativeCroppingString.java +++ b/src/main/java/io/wcm/handler/mediasource/dam/impl/weboptimized/RelativeCroppingString.java @@ -59,7 +59,10 @@ private RelativeCroppingString() { } private static String toPercentage(double fraction) { - return DECIMAL_FORMAT.format(Math.round(fraction * 1000d) / 10d); + double percentage = Math.round(fraction * 1000d) / 10d; + percentage = Math.max(0.0, percentage); + percentage = Math.min(100.0, percentage); + return DECIMAL_FORMAT.format(percentage); } }