This commit is contained in:
jrandom
2005-11-11 10:09:04 +00:00
committed by zzz
parent a8ea239dcc
commit 12ddaff0ce
3 changed files with 22 additions and 17 deletions

View File

@ -900,7 +900,9 @@ public class HTMLRenderer extends EventReceiverImpl {
} }
public static final String sanitizeString(String str) { return sanitizeString(str, true); } public static final String sanitizeString(String str) { return sanitizeString(str, true); }
public static final String sanitizeString(String str, boolean allowNL) { public static final String sanitizeString(String str, int maxLen) { return sanitizeString(str, true, maxLen); }
public static final String sanitizeString(String str, boolean allowNL) { return sanitizeString(str, allowNL, -1); }
public static final String sanitizeString(String str, boolean allowNL, int maxLen) {
if (str == null) return null; if (str == null) return null;
boolean unsafe = false; boolean unsafe = false;
unsafe = unsafe || str.indexOf('<') >= 0; unsafe = unsafe || str.indexOf('<') >= 0;
@ -910,21 +912,24 @@ public class HTMLRenderer extends EventReceiverImpl {
unsafe = unsafe || str.indexOf('\r') >= 0; unsafe = unsafe || str.indexOf('\r') >= 0;
unsafe = unsafe || str.indexOf('\f') >= 0; unsafe = unsafe || str.indexOf('\f') >= 0;
} }
if (!unsafe) return str; if (unsafe) {
//str = str.replace('<', '_'); // this should be &lt;
//str = str.replace('<', '_'); // this should be &lt; //str = str.replace('>', '-'); // this should be &gt;
//str = str.replace('>', '-'); // this should be &gt; str = str.replaceAll("<", "&lt;");
str = str.replaceAll("<", "&lt;"); str = str.replaceAll(">", "&gt;");
str = str.replaceAll(">", "&gt;"); if (!allowNL) {
if (!allowNL) { //str = str.replace('\n', ' ');
//str = str.replace('\n', ' '); //str = str.replace('\r', ' ');
//str = str.replace('\r', ' '); //str = str.replace('\f', ' ');
//str = str.replace('\f', ' '); str = str.replaceAll("\n", "<br />"); // no class
str = str.replaceAll("\n", "<br />"); // no class str = str.replaceAll("\r", "<br />"); // no class
str = str.replaceAll("\r", "<br />"); // no class str = str.replaceAll("\f", "<br />"); // no class
str = str.replaceAll("\f", "<br />"); // no class }
} }
return str; if ( (maxLen > 0) && (str.length() > maxLen) )
return str.substring(0, maxLen) + "...";
else
return str;
} }
public static final String sanitizeURL(String str) { public static final String sanitizeURL(String str) {

View File

@ -294,7 +294,7 @@ public class ThreadedHTMLRenderer extends HTMLRenderer {
_postBodyBuffer.append("schema=").append(sanitizeURL(l.schema)).append('&'); _postBodyBuffer.append("schema=").append(sanitizeURL(l.schema)).append('&');
if (l.location != null) if (l.location != null)
_postBodyBuffer.append("location=").append(sanitizeURL(l.location)).append('&'); _postBodyBuffer.append("location=").append(sanitizeURL(l.location)).append('&');
_postBodyBuffer.append("\">").append(sanitizeString(l.location)); _postBodyBuffer.append("\">").append(sanitizeString(l.location, 60));
_postBodyBuffer.append(getSpan("summDetailExternalNet")).append(" (").append(sanitizeString(l.schema)).append(")</span></a> "); _postBodyBuffer.append(getSpan("summDetailExternalNet")).append(" (").append(sanitizeString(l.schema)).append(")</span></a> ");
} }
_postBodyBuffer.append("<br />\n"); _postBodyBuffer.append("<br />\n");

View File

@ -32,7 +32,7 @@ public class PetName {
_groups = new ArrayList(); _groups = new ArrayList();
StringTokenizer tok = new StringTokenizer(dbLine, ":\n", true); StringTokenizer tok = new StringTokenizer(dbLine, ":\n", true);
int tokens = tok.countTokens(); int tokens = tok.countTokens();
System.out.println("Tokens: " + tokens); //System.out.println("Tokens: " + tokens);
if (tokens < 7) { if (tokens < 7) {
return; return;
} }