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.
This commit is contained in:
Ludy 2025-06-18 18:00:39 +02:00 committed by GitHub
parent 8632ccb870
commit cdd1ab704f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -13,6 +13,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.UUID; import java.util.UUID;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
@ -199,11 +200,11 @@ public class GeneralUtils {
if (bytes < 1024) { if (bytes < 1024) {
return bytes + " B"; return bytes + " B";
} else if (bytes < 1024 * 1024) { } 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) { } 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 { } 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));
} }
} }