Update Regex to remove unwanted character matching

This commit is contained in:
Pedro Fonseca 2025-04-12 01:00:47 +01:00
parent 87ade7e60b
commit 1c9f618882

View File

@ -124,14 +124,14 @@ public class AppConfig {
if (!uploadLimit || maxUploadSize == null || maxUploadSize.isEmpty()) { if (!uploadLimit || maxUploadSize == null || maxUploadSize.isEmpty()) {
return 0; return 0;
} else if (!new Regex("^[1-9][0-9]{0,2}[K|M|G]B$").matches(maxUploadSize)) { } else if (!new Regex("^[1-9][0-9]{0,2}[KMGkmg][Bb]$").matches(maxUploadSize)) {
log.error( log.error(
"Invalid maxUploadSize format. Expected format: [1-9][0-9]{0,2}[K|M|G]B, but got: {}", "Invalid maxUploadSize format. Expected format: [1-9][0-9]{0,2}[KMGkmg][Bb], but got: {}",
maxUploadSize); maxUploadSize);
return 0; return 0;
} else { } else {
String unit = maxUploadSize.replaceAll("[1-9][0-9]{0,2}", ""); String unit = maxUploadSize.replaceAll("[1-9][0-9]{0,2}", "").toUpperCase();
String number = maxUploadSize.replaceAll("[K|M|G]B", ""); String number = maxUploadSize.replaceAll("[KMGkmg][Bb]", "");
long size = Long.parseLong(number); long size = Long.parseLong(number);
return switch (unit) { return switch (unit) {
case "KB" -> size * 1024; case "KB" -> size * 1024;