From cdd1ab704f99259cb6566b2e96dac0b1b249a65e Mon Sep 17 00:00:00 2001 From: Ludy Date: Wed, 18 Jun 2025 18:00:39 +0200 Subject: [PATCH] fix: ensure locale-safe formatting in GeneralUtils.formatBytes (#3762) # Description of Changes Please provide a summary of the changes, including: - Updated `GeneralUtils.formatBytes(long bytes)` to use `Locale.US` for consistent number formatting across environments. - This resolves test failures caused by locale-specific formatting (e.g., comma vs. dot as decimal separator) that led to assertion mismatches during unit tests. see: https://github.com/Stirling-Tools/Stirling-PDF/pull/3562 --- ## Checklist ### General - [x] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [x] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md) (if applicable) - [x] I have performed a self-review of my own code - [x] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [x] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details. --- .../java/stirling/software/common/util/GeneralUtils.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/stirling/software/common/util/GeneralUtils.java b/common/src/main/java/stirling/software/common/util/GeneralUtils.java index 3353cdfeb..87496294d 100644 --- a/common/src/main/java/stirling/software/common/util/GeneralUtils.java +++ b/common/src/main/java/stirling/software/common/util/GeneralUtils.java @@ -13,6 +13,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Enumeration; import java.util.List; +import java.util.Locale; import java.util.UUID; import org.springframework.core.io.Resource; @@ -199,11 +200,11 @@ public class GeneralUtils { if (bytes < 1024) { return bytes + " B"; } else if (bytes < 1024 * 1024) { - return String.format("%.2f KB", bytes / 1024.0); + return String.format(Locale.US, "%.2f KB", bytes / 1024.0); } else if (bytes < 1024 * 1024 * 1024) { - return String.format("%.2f MB", bytes / (1024.0 * 1024.0)); + return String.format(Locale.US, "%.2f MB", bytes / (1024.0 * 1024.0)); } else { - return String.format("%.2f GB", bytes / (1024.0 * 1024.0 * 1024.0)); + return String.format(Locale.US, "%.2f GB", bytes / (1024.0 * 1024.0 * 1024.0)); } }