Escape HTML in dynmap description setting

Fixed editing descriptions not properly checking for illegal characters
This commit is contained in:
William278 committed 2020-12-16 01:29:43 +00:00
1 parent 7fef9ea0f1
commit f1a1df6858
10 files changed
+44 -22

No files matched your search

@@ -53,7 +53,7 @@ public class editHomeCommand implements CommandExecutor {
String newDescriptionString = newDescription.toString();
// Check the description is valid
if (!newDescriptionString.matches("[a-zA-Z0-9\\d\\-_\\s]+") && newDescriptionString.length() > 255) {
if (!newDescriptionString.matches("[a-zA-Z0-9\\d\\-_\\s]+") || newDescriptionString.length() > 255) {
messageManager.sendMessage(p, "error_edit_home_invalid_description");
return true;
}
@@ -117,7 +117,7 @@ public class editHomeCommand implements CommandExecutor {
if (!economy.takeMoney(p, publicHomeCost)) {
messageManager.sendMessage(p, "error_insufficient_funds", economy.format(publicHomeCost));
} else {
messageManager.sendMessage(p, "edit_home_privacy_public_success_economy", economy.format(publicHomeCost));
messageManager.sendMessage(p, "edit_home_privacy_public_success_economy", homeName, economy.format(publicHomeCost));
}
} else {
messageManager.sendMessage(p, "edit_home_privacy_public_success", homeName);
@@ -40,8 +40,6 @@ public class editWarpCommand implements CommandExecutor {
return true;
case "description":
if (args.length >= 3) {
Warp descriptionChangedWarp = dataManager.getWarp(warpName);
// Get the new description
StringBuilder newDescription = new StringBuilder();
for (int i = 2; i < args.length; i++) {
@@ -54,7 +52,7 @@ public class editWarpCommand implements CommandExecutor {
String newDescriptionString = newDescription.toString();
// Check the description is valid
if (!newDescriptionString.matches("[a-zA-Z0-9\\d\\-_\\s]+") && newDescriptionString.length() > 255) {
if (!newDescriptionString.matches("[a-zA-Z0-9\\d\\-_\\s]+") || newDescriptionString.length() > 255) {
messageManager.sendMessage(p, "error_edit_warp_invalid_description");
return true;
}
@@ -66,7 +64,8 @@ public class editWarpCommand implements CommandExecutor {
// Update description
dataManager.updateWarpDescription(warpName, newDescriptionString);
descriptionChangedWarp.setName(newDescriptionString);
Warp descriptionChangedWarp = dataManager.getWarp(warpName);
descriptionChangedWarp.setDescription(newDescriptionString);
if (Main.settings.doDynmap() && Main.settings.showWarpsOnDynmap()) {
dynamicMap.addDynamicMapMarker(descriptionChangedWarp);
}
@@ -1,12 +1,17 @@
package me.william278.huskhomes2.Commands;
import me.william278.huskhomes2.*;
import me.william278.huskhomes2.Objects.Home;
import me.william278.huskhomes2.dataManager;
import me.william278.huskhomes2.listHandler;
import me.william278.huskhomes2.messageManager;
import me.william278.huskhomes2.teleportManager;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
public class homeCommand implements CommandExecutor {
@Override
@@ -22,6 +27,14 @@ public class homeCommand implements CommandExecutor {
messageManager.sendMessage(p, "error_home_invalid", homeName);
}
} else {
ArrayList<Home> homes = dataManager.getPlayerHomes(p.getName());
if (homes != null) {
if (homes.size() == 1) {
// Teleport the player if they only have one home
teleportManager.queueTimedTeleport(p, homes.get(0));
return true;
}
}
listHandler.displayPlayerHomeList(p, 1);
}
return true;
@@ -29,4 +42,4 @@ public class homeCommand implements CommandExecutor {
return false;
}
}
}
@@ -1,5 +1,6 @@
package me.william278.huskhomes2.Commands;
import me.william278.huskhomes2.dataManager;
import me.william278.huskhomes2.messageManager;
import me.william278.huskhomes2.settingHandler;
import org.bukkit.command.Command;
@@ -17,7 +18,12 @@ public class setHomeCommand implements CommandExecutor {
String homeName = args[0];
settingHandler.setHome(p.getLocation(), p, homeName);
} else {
messageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
if (dataManager.getPlayerHomes(p.getName()).size() == 0) {
// If the player hasn't set a home yet, set one called "home"
settingHandler.setHome(p.getLocation(), p, "home");
} else {
messageManager.sendMessage(p, "error_invalid_syntax", command.getUsage());
}
}
return true;
}
@@ -16,6 +16,7 @@ public class setSpawnCommand implements CommandExecutor {
Player p = (Player) sender;
if (Main.settings.doSpawnCommand()) {
settingHandler.setSpawnLocation(p.getLocation());
p.getLocation().getWorld().setSpawnLocation(p.getLocation());
messageManager.sendMessage(p, "set_spawn_success");
} else {
messageManager.sendMessage(p, "error_command_disabled");
@@ -17,6 +17,7 @@ public class onPlayerJoin implements Listener {
// Create player on SQL if they don't exist already
if (!dataManager.playerExists(p)) {
dataManager.createPlayer(p);
p.teleport(teleportManager.spawnLocation.getLocation());
} else {
dataManager.checkPlayerNameChange(p);
}
@@ -9,6 +9,8 @@ import org.dynmap.DynmapAPI;
import org.dynmap.markers.Marker;
import org.dynmap.markers.MarkerSet;
import static org.apache.commons.lang.StringEscapeUtils.escapeHtml;
public class dynamicMap {
private static Plugin dynmap;
@@ -45,9 +47,9 @@ public class dynamicMap {
MarkerSet markerSet = dynmapAPI.getMarkerAPI().getMarkerSet("huskhomes.warps");
Marker m = markerSet.createMarker(markerId, warp.getName(), warp.getWorldName(), warp.getX(), warp.getY(), warp.getZ(), dynmapAPI.getMarkerAPI().getMarkerIcon(Main.settings.getDynmapWarpMarkerIconID()), false);
String popupWindow = "<div class=\"infowindow\"><span style=\"font-weight:bold;\">%WARP_NAME%</span><br/><span style=\"font-weight:bold;\">Description: </span>%DESCRIPTION%</div>";
popupWindow = popupWindow.replace("%WARP_NAME%", warp.getName());
popupWindow = popupWindow.replace("%DESCRIPTION%", warp.getDescription());
String popupWindow = "<div class=\"infowindow\"><span style=\"font-weight:bold;\">/warp %WARP_NAME%</span><br/><span style=\"font-weight:bold;\">Description: </span>%DESCRIPTION%</div>";
popupWindow = popupWindow.replace("%WARP_NAME%", escapeHtml(warp.getName()));
popupWindow = popupWindow.replace("%DESCRIPTION%", escapeHtml(warp.getDescription()));
m.setDescription(popupWindow);
} catch (Exception e) {
plugin.getLogger().severe("Error adding warp marker to the Dynamic Map (" + e.getCause() + ")");
@@ -62,10 +64,10 @@ public class dynamicMap {
MarkerSet markerSet = dynmapAPI.getMarkerAPI().getMarkerSet("huskhomes.public_homes");
Marker m = markerSet.createMarker(markerId, home.getName(), home.getWorldName(), home.getX(), home.getY(), home.getZ(), dynmapAPI.getMarkerAPI().getMarkerIcon(Main.settings.getDynmapPublicHomeMarkerIconID()), false);
String popupWindow = "<div class=\"infowindow\"><span style=\"font-weight:bold;\">%HOME_NAME%</span><br/><span style=\"font-weight:bold;\">Owner: </span>%OWNER%<br/><span style=\"font-weight:bold;\">Description: </span>%DESCRIPTION%</div>";
popupWindow = popupWindow.replace("%HOME_NAME%", home.getName());
popupWindow = popupWindow.replace("%OWNER%", home.getOwnerUsername());
popupWindow = popupWindow.replace("%DESCRIPTION%", home.getDescription());
String popupWindow = "<div class=\"infowindow\"><span style=\"font-weight:bold;\">/phome %HOME_NAME%</span><br/><span style=\"font-weight:bold;\">Owner: </span>%OWNER%<br/><span style=\"font-weight:bold;\">Description: </span>%DESCRIPTION%</div>";
popupWindow = popupWindow.replace("%HOME_NAME%", escapeHtml(home.getName()));
popupWindow = popupWindow.replace("%OWNER%", escapeHtml(home.getOwnerUsername()));
popupWindow = popupWindow.replace("%DESCRIPTION%", escapeHtml(home.getDescription()));
m.setDescription(popupWindow);
} catch (Exception e) {
plugin.getLogger().severe("Error adding public home marker to the Dynamic Map (" + e.getCause() + ")");