diff --git a/main/ui/src/main/java/org/cryptomator/ui/controllers/SettingsController.java b/main/ui/src/main/java/org/cryptomator/ui/controllers/SettingsController.java index a2984623b..e0494ee37 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/controllers/SettingsController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/controllers/SettingsController.java @@ -14,11 +14,13 @@ import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; -import org.apache.commons.lang3.CharUtils; import org.apache.commons.lang3.SystemUtils; import org.cryptomator.common.settings.Settings; import org.cryptomator.ui.settings.Localization; +import com.google.common.base.CharMatcher; +import com.google.common.base.Strings; + import javafx.beans.binding.Bindings; import javafx.event.ActionEvent; import javafx.fxml.FXML; @@ -34,6 +36,8 @@ import javafx.scene.layout.VBox; @Singleton public class SettingsController implements ViewController { + private static final CharMatcher DIGITS_MATCHER = CharMatcher.inRange('0', '9'); + private final Localization localization; private final Settings settings; private final Optional applicationVersion; @@ -130,11 +134,7 @@ public class SettingsController implements ViewController { } private void filterNumericKeyEvents(KeyEvent t) { - if (t.getCharacter() == null || t.getCharacter().length() == 0) { - return; - } - char c = CharUtils.toChar(t.getCharacter()); - if (!(CharUtils.isAsciiNumeric(c) || c == '_')) { + if (!Strings.isNullOrEmpty(t.getCharacter()) && !DIGITS_MATCHER.matchesAllOf(t.getCharacter())) { t.consume(); } } diff --git a/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockController.java b/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockController.java index a3b624c82..0c8f79434 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockController.java @@ -31,6 +31,9 @@ import org.cryptomator.ui.util.DialogBuilderUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.common.base.CharMatcher; +import com.google.common.base.Strings; + import javafx.application.Application; import javafx.application.Platform; import javafx.beans.value.ChangeListener; @@ -55,6 +58,11 @@ import javafx.util.StringConverter; public class UnlockController implements ViewController { private static final Logger LOG = LoggerFactory.getLogger(UnlockController.class); + private static final CharMatcher ALPHA_NUMERIC_MATCHER = CharMatcher.inRange('a', 'z') // + .or(CharMatcher.inRange('A', 'Z')) // + .or(CharMatcher.inRange('0', '9')) // + .or(CharMatcher.is('_')) // + .precomputed(); private final Application app; private final Localization localization; @@ -212,11 +220,7 @@ public class UnlockController implements ViewController { } private void filterAlphanumericKeyEvents(KeyEvent t) { - if (t.getCharacter() == null || t.getCharacter().length() == 0) { - return; - } - char c = CharUtils.toChar(t.getCharacter()); - if (!(CharUtils.isAsciiAlphanumeric(c) || c == '_')) { + if (!Strings.isNullOrEmpty(t.getCharacter()) && !ALPHA_NUMERIC_MATCHER.matchesAllOf(t.getCharacter())) { t.consume(); } }