Handle manual edits of markers.yml, update of non-markup values

This commit is contained in:
Mike Primm 2022-01-12 22:19:12 -06:00
parent 04ef31fa3b
commit b85a159bda
6 changed files with 25 additions and 4 deletions

View File

@ -325,6 +325,9 @@ public class Client {
case '>':
str.append(">");
break;
case '\'':
str.append("'");
break;
default:
str.append(c);
break;

View File

@ -120,8 +120,8 @@ class AreaMarkerImpl implements AreaMarker, EnterExitMarker {
* @param node - configuration node
*/
boolean loadPersistentData(ConfigurationNode node) {
label = node.getString("label", markerid);
markup = node.getBoolean("markup", false);
label = MarkerAPIImpl.escapeForHTMLIfNeeded(node.getString("label", markerid), markup);
ytop = node.getDouble("ytop", 64.0);
ybottom = node.getDouble("ybottom", 64.0);
List<Double> xx = node.getList("x");

View File

@ -102,8 +102,8 @@ class CircleMarkerImpl implements CircleMarker, EnterExitMarker {
* @param node - configuration node
*/
boolean loadPersistentData(ConfigurationNode node) {
label = node.getString("label", markerid);
markup = node.getBoolean("markup", false);
label = MarkerAPIImpl.escapeForHTMLIfNeeded(node.getString("label", markerid), markup);
world = node.getString("world", "world");
normalized_world = DynmapWorld.normalizeWorldName(world);
x = node.getDouble("x", 0);

View File

@ -3558,4 +3558,22 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
ms.addEnteredMarkers(entered, worldid, x, y, z);
}
}
/**
* Check if loaded string needs to be escaped (if non-markup)
*/
public static String escapeForHTMLIfNeeded(String txt, boolean markup) {
if (markup) return txt; // Not needed for markup
// If escaped properly, these characters aren't present (all but ampersand of HTML active characrers
if (txt != null) {
if ((txt.indexOf('<') >= 0) || (txt.indexOf('>') >= 0) || (txt.indexOf('\'') >= 0) || (txt.indexOf('"') >= 0)) {
return Client.encodeForHTML(txt);
}
// If ampersand without semicolon after (simplistic check for ampersand without being escape sequence)
int idx = txt.lastIndexOf('&');
if ((idx >= 0) && (txt.indexOf(';', idx) < 0)) {
return Client.encodeForHTML(txt);
}
}
return txt;
}
}

View File

@ -76,8 +76,8 @@ class MarkerImpl implements Marker {
* @param node - configuration node
*/
boolean loadPersistentData(ConfigurationNode node) {
label = node.getString("label", markerid);
markup = node.getBoolean("markup", false);
label = MarkerAPIImpl.escapeForHTMLIfNeeded(node.getString("label", markerid), markup);
x = node.getDouble("x", 0);
y = node.getDouble("y", 64);
z = node.getDouble("z", 0);

View File

@ -87,8 +87,8 @@ class PolyLineMarkerImpl implements PolyLineMarker {
* @param node - configuration node
*/
boolean loadPersistentData(ConfigurationNode node) {
label = node.getString("label", markerid);
markup = node.getBoolean("markup", false);
label = MarkerAPIImpl.escapeForHTMLIfNeeded(node.getString("label", markerid), markup);
List<Double> xx = node.getList("x");
List<Double> yy = node.getList("y");
List<Double> zz = node.getList("z");