3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-17 05:20:14 +01:00

Move and rename key escaping methods while I'm here

Dieser Commit ist enthalten in:
Mark Vainomaa 2018-10-28 18:18:44 +02:00
Ursprung 0c86f02c49
Commit e0330e9f27
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 1B3F9523B542D315
2 geänderte Dateien mit 13 neuen und 13 gelöschten Zeilen

Datei anzeigen

@ -125,7 +125,7 @@ public abstract class AnnotatedConfig {
// Get a key name for config. Use field name if @ConfigKey annotation is not present. // Get a key name for config. Use field name if @ConfigKey annotation is not present.
ConfigKey key = field.getAnnotation(ConfigKey.class); ConfigKey key = field.getAnnotation(ConfigKey.class);
final String name = safeKey(key == null ? field.getName() : key.value()); final String name = escapeKeyIfNeeded(key == null ? field.getName() : key.value());
Object value = field.get(dumpable); Object value = field.get(dumpable);
@ -142,7 +142,7 @@ public abstract class AnnotatedConfig {
Map<String, ?> map = (Map<String, ?>) value; Map<String, ?> map = (Map<String, ?>) value;
for (Entry<String, ?> entry : map.entrySet()) { for (Entry<String, ?> entry : map.entrySet()) {
lines.add( lines.add(
safeKey(entry.getKey()) + " = " + serialize(entry.getValue())); // Save map data escapeKeyIfNeeded(entry.getKey()) + " = " + serialize(entry.getValue())); // Save map data
} }
lines.add(""); // Add empty line lines.add(""); // Add empty line
continue; continue;
@ -203,7 +203,7 @@ public abstract class AnnotatedConfig {
return value != null ? value.toString() : "null"; return value != null ? value.toString() : "null";
} }
private static String safeKey(String key) { protected static String escapeKeyIfNeeded(String key) {
if (key.contains(".") && !(key.indexOf('"') == 0 && key.lastIndexOf('"') == (key.length() if (key.contains(".") && !(key.indexOf('"') == 0 && key.lastIndexOf('"') == (key.length()
- 1))) { - 1))) {
return '"' + key + '"'; return '"' + key + '"';
@ -211,6 +211,14 @@ public abstract class AnnotatedConfig {
return key; return key;
} }
protected static String unesacpeKeyIfNeeded(String key) {
int lastIndex;
if (key.indexOf('"') == 0 && (lastIndex = key.lastIndexOf('"')) == (key.length() - 1)) {
return key.substring(1, lastIndex);
}
return key;
}
/** /**
* Writes list of strings to file. * Writes list of strings to file.
* *

Datei anzeigen

@ -487,9 +487,9 @@ public class VelocityConfiguration extends AnnotatedConfig implements ProxyConfi
for (Map.Entry<String, Object> entry : toml.entrySet()) { for (Map.Entry<String, Object> entry : toml.entrySet()) {
if (entry.getValue() instanceof String) { if (entry.getValue() instanceof String) {
forcedHosts forcedHosts
.put(stripQuotes(entry.getKey()), ImmutableList.of((String) entry.getValue())); .put(unesacpeKeyIfNeeded(entry.getKey()), ImmutableList.of((String) entry.getValue()));
} else if (entry.getValue() instanceof List) { } else if (entry.getValue() instanceof List) {
forcedHosts.put(stripQuotes(entry.getKey()), forcedHosts.put(unesacpeKeyIfNeeded(entry.getKey()),
ImmutableList.copyOf((List<String>) entry.getValue())); ImmutableList.copyOf((List<String>) entry.getValue()));
} else { } else {
throw new IllegalStateException( throw new IllegalStateException(
@ -512,14 +512,6 @@ public class VelocityConfiguration extends AnnotatedConfig implements ProxyConfi
this.forcedHosts = forcedHosts; this.forcedHosts = forcedHosts;
} }
private static String stripQuotes(String key) {
int lastIndex;
if (key.indexOf('"') == 0 && (lastIndex = key.lastIndexOf('"')) == (key.length() - 1)) {
return key.substring(1, lastIndex);
}
return key;
}
@Override @Override
public String toString() { public String toString() {
return "ForcedHosts{" return "ForcedHosts{"