Windows-Zeichenbehandlung im finalen Basis-Dateinamen explizit umgesetzt

This commit is contained in:
2026-04-07 13:59:18 +02:00
parent f81f30c7ea
commit 7e4201b651
2 changed files with 114 additions and 3 deletions
@@ -97,6 +97,11 @@ public final class TargetFilenameBuildingService {
* If any rule is violated, the state is treated as an
* {@link InconsistentProposalState}.
* <p>
* Windows compatibility: The final filename is cleaned of Windows-incompatible characters
* (e.g., {@code < > : " / \ | ? *}) to ensure the resulting filename can be created on
* Windows systems. This is a defensive measure; the validated title is already expected
* to contain only letters, digits, and spaces.
* <p>
* The 20-character limit applies exclusively to the base title. A duplicate-avoidance
* suffix (e.g., {@code (1)}) may be appended by the target folder adapter after this
* method returns and is not counted against the 20 characters.
@@ -134,8 +139,16 @@ public final class TargetFilenameBuildingService {
+ title + "'");
}
// Defensive Windows compatibility: remove Windows-incompatible characters
String cleanedTitle = removeWindowsIncompatibleCharacters(title);
if (cleanedTitle.isBlank()) {
return new InconsistentProposalState(
"Title becomes empty after Windows-compatibility cleaning: '"
+ title + "'");
}
// Build: YYYY-MM-DD - Titel.pdf
String baseFilename = date + " - " + title + ".pdf";
String baseFilename = date + " - " + cleanedTitle + ".pdf";
return new BaseFilenameReady(baseFilename);
}
@@ -156,4 +169,21 @@ public final class TargetFilenameBuildingService {
}
return true;
}
/**
* Removes characters that are incompatible with Windows filenames.
* <p>
* Windows-incompatible characters are: {@code < > : " / \ | ? *}
* <p>
* This is a defensive measure for ensuring Windows compatibility. The characters are
* simply removed; no replacement is performed. Unicode letters (including Umlauts and ß)
* and spaces are retained.
*
* @param title the title to clean; must not be null
* @return the cleaned title with Windows-incompatible characters removed
*/
private static String removeWindowsIncompatibleCharacters(String title) {
// Windows-incompatible characters: < > : " / \ | ? *
return title.replaceAll("[<>:\"/\\\\|?*]", "");
}
}