mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-23 05:01:28 +00:00
refined normalize Method, fxied Tests for it:
* all unicode spaces are now replaced with \u0020 * if the end string only contains whitspaces, "_" will be returned
This commit is contained in:
@@ -79,18 +79,25 @@ public class VaultSettings {
|
||||
String normalizeDisplayName() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
Set<Integer> notAllowedCharacters = "<>:\"/\\|?*".chars().boxed().collect(Collectors.toUnmodifiableSet());
|
||||
|
||||
if (displayName.isEmpty().get() || displayName.getValueSafe().equals(".") || displayName.getValueSafe().equals("..")) {
|
||||
builder.append("_");
|
||||
} else {
|
||||
displayName.get().codePoints().forEach(codePoint -> {
|
||||
if (Character.isDefined(codePoint) && !Character.isIdentifierIgnorable(codePoint) && !notAllowedCharacters.contains(codePoint)) {
|
||||
builder.appendCodePoint(codePoint);
|
||||
} else {
|
||||
builder.append("_");
|
||||
}
|
||||
});
|
||||
return builder.append("_").toString();
|
||||
}
|
||||
|
||||
displayName.get().codePoints().forEach(codePoint -> {
|
||||
if (Character.isDefined(codePoint) && !Character.isIdentifierIgnorable(codePoint) && !notAllowedCharacters.contains(codePoint)) {
|
||||
builder.appendCodePoint(Character.isWhitespace(codePoint) || Character.isSpaceChar(codePoint) ? 0x020 : codePoint);
|
||||
} else {
|
||||
builder.append("_");
|
||||
}
|
||||
});
|
||||
|
||||
String result = builder.toString();
|
||||
if (!result.isBlank()) {
|
||||
return result;
|
||||
} else {
|
||||
return "_";
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/* Getter/Setter */
|
||||
|
||||
@@ -16,7 +16,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
public class VaultSettingsTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({"a a,a_a", "ä,a", "Ĉ,C", ":,_", "汉语,_"})
|
||||
@CsvSource({"a\u000Fa,a_a", ": \\,_ _", "汉语,汉语", "..,_", "a\ta,a\u0020a", "\t\n\r,_"})
|
||||
public void testNormalize(String test, String expected) {
|
||||
VaultSettings settings = new VaultSettings("id");
|
||||
settings.displayName().setValue(test);
|
||||
|
||||
Reference in New Issue
Block a user