From a40830434d5311212f0580dc3fe4442385068dfd Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Sun, 5 Dec 2021 20:32:22 -0600 Subject: [PATCH] Handle fields in yaml config files with "/" - fix for #3533 --- DynmapCore/build.gradle | 2 +- .../java/org/dynmap/ConfigurationNode.java | 6 +++-- .../dynmap/markers/impl/MarkerSetImpl.java | 26 +++++++++++-------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/DynmapCore/build.gradle b/DynmapCore/build.gradle index fabfd87d..bec8019f 100644 --- a/DynmapCore/build.gradle +++ b/DynmapCore/build.gradle @@ -6,7 +6,7 @@ dependencies { implementation 'org.eclipse.jetty:jetty-server:9.4.26.v20200117' implementation 'org.eclipse.jetty:jetty-servlet:9.4.26.v20200117' implementation 'com.googlecode.json-simple:json-simple:1.1.1' - implementation 'org.yaml:snakeyaml:1.23' + implementation 'org.yaml:snakeyaml:1.29' implementation 'com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer:20180219.1' implementation 'org.postgresql:postgresql:42.2.18' } diff --git a/DynmapCore/src/main/java/org/dynmap/ConfigurationNode.java b/DynmapCore/src/main/java/org/dynmap/ConfigurationNode.java index 69135bfc..aeb995d2 100644 --- a/DynmapCore/src/main/java/org/dynmap/ConfigurationNode.java +++ b/DynmapCore/src/main/java/org/dynmap/ConfigurationNode.java @@ -138,9 +138,11 @@ public class ConfigurationNode implements Map { public Object getObject(String path) { if (path.isEmpty()) return entries; + // Try get first (in case '/' is legit part + Object v = get(path); int separator = path.indexOf('/'); - if (separator < 0) - return get(path); + if ((v != null) || (separator < 0)) return v; + String localKey = path.substring(0, separator); Object subvalue = get(localKey); if (subvalue == null) diff --git a/DynmapCore/src/main/java/org/dynmap/markers/impl/MarkerSetImpl.java b/DynmapCore/src/main/java/org/dynmap/markers/impl/MarkerSetImpl.java index 0708a36e..622121a9 100644 --- a/DynmapCore/src/main/java/org/dynmap/markers/impl/MarkerSetImpl.java +++ b/DynmapCore/src/main/java/org/dynmap/markers/impl/MarkerSetImpl.java @@ -452,10 +452,11 @@ class MarkerSetImpl implements MarkerSet { boolean loadPersistentData(ConfigurationNode node) { label = node.getString("label", setid); /* Get label */ ConfigurationNode markernode = node.getNode("markers"); - if(markernode != null) { + if (markernode != null) { for(String id : markernode.keySet()) { MarkerImpl marker = new MarkerImpl(id, this); /* Make and load marker */ - if(marker.loadPersistentData(markernode.getNode(id))) { + ConfigurationNode cfg = markernode.getNode(id); + if ((cfg != null) && marker.loadPersistentData(cfg)) { markers.put(id, marker); } else { @@ -465,10 +466,11 @@ class MarkerSetImpl implements MarkerSet { } } ConfigurationNode areamarkernode = node.getNode("areas"); - if(areamarkernode != null) { + if (areamarkernode != null) { for(String id : areamarkernode.keySet()) { AreaMarkerImpl marker = new AreaMarkerImpl(id, this); /* Make and load marker */ - if(marker.loadPersistentData(areamarkernode.getNode(id))) { + ConfigurationNode cfg = areamarkernode.getNode(id); + if ((cfg != null) && marker.loadPersistentData(cfg)) { areamarkers.put(id, marker); if(marker.getBoostFlag()) { if(boostingareamarkers == null) { @@ -490,10 +492,11 @@ class MarkerSetImpl implements MarkerSet { } } ConfigurationNode linemarkernode = node.getNode("lines"); - if(linemarkernode != null) { + if (linemarkernode != null) { for(String id : linemarkernode.keySet()) { PolyLineMarkerImpl marker = new PolyLineMarkerImpl(id, this); /* Make and load marker */ - if(marker.loadPersistentData(linemarkernode.getNode(id))) { + ConfigurationNode cfg = linemarkernode.getNode(id); + if ((cfg != null) && marker.loadPersistentData(cfg)) { linemarkers.put(id, marker); } else { @@ -503,10 +506,11 @@ class MarkerSetImpl implements MarkerSet { } } ConfigurationNode circlemarkernode = node.getNode("circles"); - if(circlemarkernode != null) { + if (circlemarkernode != null) { for(String id : circlemarkernode.keySet()) { CircleMarkerImpl marker = new CircleMarkerImpl(id, this); /* Make and load marker */ - if(marker.loadPersistentData(circlemarkernode.getNode(id))) { + ConfigurationNode cfg = circlemarkernode.getNode(id); + if ((cfg != null) && marker.loadPersistentData(cfg)) { circlemarkers.put(id, marker); if(marker.getBoostFlag()) { if(boostingcirclemarkers == null) { @@ -528,7 +532,7 @@ class MarkerSetImpl implements MarkerSet { } } List allowed = node.getList("allowedicons"); - if(allowed != null) { + if (allowed != null) { for(String id : allowed) { MarkerIconImpl icon = MarkerAPIImpl.getMarkerIconImpl(id); if(icon != null) @@ -542,12 +546,12 @@ class MarkerSetImpl implements MarkerSet { minzoom = node.getInteger("minzoom", -1); maxzoom = node.getInteger("maxzoom", -1); if (minzoom == 0) minzoom = -1; - if(node.containsKey("showlabels")) + if (node.containsKey("showlabels")) showlabels = node.getBoolean("showlabels", false); else showlabels = null; String defid = node.getString("deficon"); - if((defid != null) && (MarkerAPIImpl.api != null)) { + if ((defid != null) && (MarkerAPIImpl.api != null)) { deficon = MarkerAPIImpl.getMarkerIconImpl(defid); } else {