* replaceAll() -> replace() when not using regex

* ampersand escaping (lots more to do)
This commit is contained in:
zzz
2010-10-19 14:39:29 +00:00
parent 8c7a39f00a
commit 466128c179
6 changed files with 12 additions and 8 deletions

View File

@ -1214,7 +1214,9 @@ public class I2PSnarkServlet extends Default {
/** @since 0.7.14 */ /** @since 0.7.14 */
private static String urlify(String s) { private static String urlify(String s) {
StringBuilder buf = new StringBuilder(256); StringBuilder buf = new StringBuilder(256);
buf.append("<a href=\"").append(s).append("\">").append(s).append("</a>"); // browsers seem to work without doing this but let's be strict
String link = s.replace("&", "&amp;");
buf.append("<a href=\"").append(link).append("\">").append(link).append("</a>");
return buf.toString(); return buf.toString();
} }

View File

@ -175,7 +175,7 @@ public class EditBean extends IndexBean {
} }
public String getAccessList(int tunnel) { public String getAccessList(int tunnel) {
return getProperty(tunnel, "i2cp.accessList", "").replaceAll(",", "\n"); return getProperty(tunnel, "i2cp.accessList", "").replace(",", "\n");
} }
public boolean getClose(int tunnel) { public boolean getClose(int tunnel) {

View File

@ -666,7 +666,7 @@ public class IndexBean {
} }
public void setAccessList(String val) { public void setAccessList(String val) {
if (val != null) if (val != null)
_otherOptions.put("i2cp.accessList", val.trim().replaceAll("\r\n", ",").replaceAll("\n", ",").replaceAll(" ", ",")); _otherOptions.put("i2cp.accessList", val.trim().replace("\r\n", ",").replace("\n", ",").replace(" ", ","));
} }
public void setCloseTime(String val) { public void setCloseTime(String val) {
if (val != null) { if (val != null) {

View File

@ -142,7 +142,7 @@ public class ConfigUpdateHandler extends FormHandler {
} }
if ( (_updateURL != null) && (_updateURL.length() > 0) ) { if ( (_updateURL != null) && (_updateURL.length() > 0) ) {
_updateURL = _updateURL.replaceAll("\r\n", ",").replaceAll("\n", ","); _updateURL = _updateURL.replace("\r\n", ",").replace("\n", ",");
String oldURL = _context.router().getConfigSetting(PROP_UPDATE_URL); String oldURL = _context.router().getConfigSetting(PROP_UPDATE_URL);
if ( (oldURL == null) || (!_updateURL.equals(oldURL)) ) { if ( (oldURL == null) || (!_updateURL.equals(oldURL)) ) {
_context.router().setConfigSetting(PROP_UPDATE_URL, _updateURL); _context.router().setConfigSetting(PROP_UPDATE_URL, _updateURL);
@ -151,7 +151,7 @@ public class ConfigUpdateHandler extends FormHandler {
} }
if ( (_trustedKeys != null) && (_trustedKeys.length() > 0) ) { if ( (_trustedKeys != null) && (_trustedKeys.length() > 0) ) {
_trustedKeys = _trustedKeys.replaceAll("\r\n", ",").replaceAll("\n", ","); _trustedKeys = _trustedKeys.replace("\r\n", ",").replace("\n", ",");
String oldKeys = new TrustedUpdate(_context).getTrustedKeysString(); String oldKeys = new TrustedUpdate(_context).getTrustedKeysString();
if ( (oldKeys == null) || (!_trustedKeys.equals(oldKeys)) ) { if ( (oldKeys == null) || (!_trustedKeys.equals(oldKeys)) ) {
_context.router().setConfigSetting(PROP_TRUSTED_KEYS, _trustedKeys); _context.router().setConfigSetting(PROP_TRUSTED_KEYS, _trustedKeys);

View File

@ -40,7 +40,7 @@ public class ConfigUpdateHelper extends HelperBase {
public String getUpdateURL() { public String getUpdateURL() {
String url = _context.getProperty(ConfigUpdateHandler.PROP_UPDATE_URL); String url = _context.getProperty(ConfigUpdateHandler.PROP_UPDATE_URL);
if (url != null) if (url != null)
return url.replaceAll(",", "\n"); return url.replace(",", "\n");
else else
return ConfigUpdateHandler.DEFAULT_UPDATE_URL; return ConfigUpdateHandler.DEFAULT_UPDATE_URL;
} }

View File

@ -33,7 +33,7 @@ public class LogsHelper extends HelperBase {
if (str == null) if (str == null)
return ""; return "";
else { else {
str = str.replaceAll("<", "&lt;").replaceAll(">", "&gt;"); str = str.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;");
return _("File location") + ": <b><code>" + f.getAbsolutePath() + "</code></b> <pre>" + str + "</pre>"; return _("File location") + ": <b><code>" + f.getAbsolutePath() + "</code></b> <pre>" + str + "</pre>";
} }
} }
@ -54,12 +54,14 @@ public class LogsHelper extends HelperBase {
buf.append("<code>\n"); buf.append("<code>\n");
for (int i = msgs.size(); i > 0; i--) { for (int i = msgs.size(); i > 0; i--) {
String msg = msgs.get(i - 1); String msg = msgs.get(i - 1);
msg = msg.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;");
buf.append("<li>"); buf.append("<li>");
if (colorize) { if (colorize) {
String color; String color;
// Homeland Security Advisory System // Homeland Security Advisory System
// http://www.dhs.gov/xinfoshare/programs/Copy_of_press_release_0046.shtm // http://www.dhs.gov/xinfoshare/programs/Copy_of_press_release_0046.shtm
// but pink instead of yellow for WARN // but pink instead of yellow for WARN
// FIXME doesnt work for translated levels
if (msg.contains("CRIT")) if (msg.contains("CRIT"))
color = "#cc0000"; color = "#cc0000";
else if (msg.contains("ERROR")) else if (msg.contains("ERROR"))
@ -71,7 +73,7 @@ public class LogsHelper extends HelperBase {
else else
color = "#006600"; color = "#006600";
buf.append("<font color=\"").append(color).append("\">"); buf.append("<font color=\"").append(color).append("\">");
buf.append(msg.replaceAll("<", "&lt;").replaceAll(">", "&gt;")); buf.append(msg);
buf.append("</font>"); buf.append("</font>");
} else { } else {
buf.append(msg); buf.append(msg);