From 8fba9d7438c89fcbb99f6c35f41765c57d5c3267 Mon Sep 17 00:00:00 2001 From: Crypnotic Date: Sun, 9 Feb 2020 13:40:15 -0600 Subject: [PATCH] Add cleanServerName to VelocityConfiguration to remove quotes and other unforeseen characters from server names before registration --- .../proxy/config/VelocityConfiguration.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java b/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java index 6fd13239e..3bca8dcb5 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java @@ -467,7 +467,7 @@ public class VelocityConfiguration extends AnnotatedConfig implements ProxyConfi Map servers = new HashMap<>(); for (Map.Entry entry : toml.entrySet()) { if (entry.getValue() instanceof String) { - servers.put(entry.getKey(), (String) entry.getValue()); + servers.put(cleanServerName(entry.getKey()), (String) entry.getValue()); } else { if (!entry.getKey().equalsIgnoreCase("try")) { throw new IllegalArgumentException( @@ -501,6 +501,19 @@ public class VelocityConfiguration extends AnnotatedConfig implements ProxyConfi this.attemptConnectionOrder = attemptConnectionOrder; } + /** + * TOML requires keys to match a regex of {@code [A-Za-z0-9_-]} unless it is wrapped in + * quotes; however, the TOML parser returns the key with the quotes so we need to clean the + * server name before we pass it onto server registration to keep proper server name behavior. + * + * @param name the server name to clean + * + * @return the cleaned server name + */ + private String cleanServerName(String name) { + return name.replace("\"", ""); + } + @Override public String toString() { return "Servers{"