launcher: addServer: don't allow http and filter spaces while pressing key

This commit is contained in:
Bixilon 2020-12-21 19:32:11 +01:00
parent 096279efd9
commit 8a73fefaaa
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
2 changed files with 8 additions and 7 deletions

View File

@ -33,10 +33,7 @@ import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Label;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.*;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.BorderPane;
@ -140,11 +137,15 @@ public class MainWindow implements Initializable {
RequiredFieldValidator serverAddressValidator = new RequiredFieldValidator();
serverAddressValidator.setMessage(LocaleManager.translate(Strings.SERVER_ADDRESS_INPUT_REQUIRED));
serverAddressField.getValidators().add(serverAddressValidator);
serverAddressField.focusedProperty().addListener((o, oldValue, newValue) -> {
serverAddressField.focusedProperty().addListener((observableValue, oldValue, newValue) -> {
if (!newValue) {
serverAddressField.validate();
}
});
serverAddressField.setTextFormatter(new TextFormatter<String>((change) -> {
change.setText(DNSUtil.correctHostName(change.getText()));
return change;
}));
GUITools.VERSION_COMBO_BOX.getSelectionModel().select(Versions.LOWEST_VERSION_SUPPORTED);

View File

@ -18,6 +18,7 @@ import org.xbill.DNS.Record;
import org.xbill.DNS.*;
import java.util.LinkedList;
import java.util.Locale;
public final class DNSUtil {
@ -53,7 +54,6 @@ public final class DNSUtil {
public static String correctHostName(String hostname) {
// replaces invalid chars to avoid copy and paste issues (like spaces, ...)
hostname = hostname.replaceAll("\\s", "");
return hostname.toLowerCase();
return hostname.replaceAll("\\s+|((https|http):/{2})+|/", "").toLowerCase(Locale.ROOT);
}
}