diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHandler.java b/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHandler.java index 90be37ad2e0b6439bc6e6bd48ce2f8b26982e9b5..b65d58fb6b78eb5d2a9ee4b866cdb14047b97536 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHandler.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHandler.java @@ -10,6 +10,7 @@ import java.util.Map; import java.util.Properties; import java.util.Set; +import net.i2p.data.DataHelper; import net.i2p.router.client.ClientManagerFacadeImpl; import net.i2p.router.startup.ClientAppConfig; import net.i2p.router.startup.LoadClientAppsJob; @@ -165,7 +166,7 @@ public class ConfigClientsHandler extends FormHandler { if (! ("webConsole".equals(ca.clientName) || "Web console".equals(ca.clientName))) ca.disabled = val == null; // edit of an existing entry - String desc = unescapeHTML(getJettyString("desc" + cur)); + String desc = DataHelper.unescapeHTML(getJettyString("desc" + cur)); if (desc != null) { int spc = desc.indexOf(" "); String clss = desc; @@ -181,7 +182,7 @@ public class ConfigClientsHandler extends FormHandler { } int newClient = clients.size(); - String newDesc = unescapeHTML(getJettyString("desc" + newClient)); + String newDesc = DataHelper.unescapeHTML(getJettyString("desc" + newClient)); if (newDesc != null && newDesc.trim().length() > 0) { // new entry int spc = newDesc.indexOf(" "); @@ -399,22 +400,4 @@ public class ConfigClientsHandler extends FormHandler { _context.router().saveConfig(); addFormNotice(_("Interface configuration saved successfully - restart required to take effect.")); } - - /** - * Unescapes a string taken from HTML - */ - private String unescapeHTML(String escaped) { - Map<String, String> map = new HashMap<String, String>(); - map.put(""","\""); - map.put("&","&"); - map.put("<","<"); - map.put(">",">"); - String unescaped = escaped; - for (Map.Entry<String, String> entry : map.entrySet()) { - String k = entry.getKey(); - String v = entry.getValue(); - unescaped = unescaped.replaceAll(k, v); - } - return unescaped; - } } diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHelper.java b/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHelper.java index e7033d36825b5f168c6c0529d51aabaaaf0190d3..7af27001eb6a78e9cbd584f6661cb39650fc3112 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHelper.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHelper.java @@ -3,14 +3,13 @@ package net.i2p.router.web; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; -import java.util.HashMap; import java.util.Iterator; import java.util.List; -import java.util.Map; import java.util.Properties; import java.util.Set; import java.util.TreeSet; +import net.i2p.data.DataHelper; import net.i2p.router.client.ClientManagerFacadeImpl; import net.i2p.router.startup.ClientAppConfig; import net.i2p.util.Addresses; @@ -236,7 +235,7 @@ public class ConfigClientsHelper extends HelperBase { boolean enabled, boolean ro, String desc, boolean edit, boolean showEditButton, boolean showUpdateButton, boolean showStopButton, boolean showDeleteButton, boolean showStartButton) { - String escapeddesc = escapeHTML(desc); + String escapeddesc = DataHelper.escapeHTML(desc); buf.append("<tr><td class=\"mediumtags\" align=\"right\" width=\"25%\">"); if (urlify && enabled) { String link = "/"; @@ -301,22 +300,4 @@ public class ConfigClientsHelper extends HelperBase { String rv = t1.replace('>', ' '); return rv; } - - /** - * Escapes a string for inclusion in HTML - */ - private String escapeHTML(String unescaped) { - Map<String, String> map = new HashMap<String, String>(); - map.put("\"","""); - map.put("&","&"); - map.put("<","<"); - map.put(">",">"); - String escaped = unescaped; - for (Map.Entry<String, String> entry : map.entrySet()) { - String k = entry.getKey(); - String v = entry.getValue(); - escaped = escaped.replaceAll(k, v); - } - return escaped; - } } diff --git a/core/java/src/net/i2p/data/DataHelper.java b/core/java/src/net/i2p/data/DataHelper.java index 03c95368d7c38c699e6c88104209ea2c9bf7890f..6dfead3b3efb652cfb9863d1b9bed857b1128e25 100644 --- a/core/java/src/net/i2p/data/DataHelper.java +++ b/core/java/src/net/i2p/data/DataHelper.java @@ -1468,6 +1468,48 @@ public class DataHelper { return rv; } + /** + * Escape a string for inclusion in HTML + * @param unescaped the unescaped string, may be null + * @return the escaped string, or an empty string if null is passed in + */ + public static String escapeHTML(String unescaped) { + if (unescaped == null) return ""; + Map<String, String> map = new HashMap<String, String>(); + map.put("\"","""); + map.put("&","&"); + map.put("<","<"); + map.put(">",">"); + String escaped = unescaped; + for (Map.Entry<String, String> entry : map.entrySet()) { + String k = entry.getKey(); + String v = entry.getValue(); + escaped = escaped.replaceAll(k, v); + } + return escaped; + } + + /** + * Unescape a string taken from HTML + * @param escaped the escaped string, may be null + * @return the unescaped string, or an empty string if null is passed in + */ + public static String unescapeHTML(String escaped) { + if (escaped == null) return ""; + Map<String, String> map = new HashMap<String, String>(); + map.put(""","\""); + map.put("&","&"); + map.put("<","<"); + map.put(">",">"); + String unescaped = escaped; + for (Map.Entry<String, String> entry : map.entrySet()) { + String k = entry.getKey(); + String v = entry.getValue(); + unescaped = unescaped.replaceAll(k, v); + } + return unescaped; + } + public static final int MAX_UNCOMPRESSED = 40*1024; public static final int MAX_COMPRESSION = Deflater.BEST_COMPRESSION; public static final int NO_COMPRESSION = Deflater.NO_COMPRESSION;