Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

*) taking back changes for replaceHTML

low012c6d58d9b9a7a
diff --git a/source/de/anomic/data/wikiCode.java b/source/de/anomic/data/wikiCode.java
index 300f3423a..bff167e23 100644
--- a/source/de/anomic/data/wikiCode.java
+++ b/source/de/anomic/data/wikiCode.java
@@ -109,131 +109,22 @@ public class wikiCode {
}
}
- //The following method has been submitted by Kane (added and a few changes by MN)
- /** Replaces special characters from a string. Otherwise they might cause ugly output on some systems.
- * This code is also important to avoid XSS attacks.
- *
- * @param text a string that possibly contains special characters
- * @return the string with all special characters encoded so they will look right on every system
- */
- public static String replaceHTML(String text) {
- if (text==null) { return null; }
- for (int x=0;x<=htmlentities.length-1;x=x+2) {
- int p=0;
- while ((p=text.indexOf(htmlentities[x],p))>=0) {
- text=text.substring(0,p)+htmlentities[x+1]+text.substring(p+htmlentities[x].length());
- p+=htmlentities[x+1].length();
- }
- }
- return text;
+ public static String replaceHTML(String result) {
+ if (result == null) return null;
+ int p0;
+
+ // Ampersands have to be replaced first. If they were replaced later,
+ // other replaced characters containing ampersands would get messed up.
+ p0 = 0; while ((p0 = result.indexOf("&", p0)) >= 0) {result = result.substring(0, p0) + "&amp;" + result.substring(p0 + 1); p0++;}
+ p0 = 0; while ((p0 = result.indexOf('"', p0)) >= 0) result = result.substring(0, p0) + "&quot;" + result.substring(p0 + 1);
+ p0 = 0; while ((p0 = result.indexOf("<", p0)) >= 0) result = result.substring(0, p0) + "&lt;" + result.substring(p0 + 1);
+ p0 = 0; while ((p0 = result.indexOf(">", p0)) >= 0) result = result.substring(0, p0) + "&gt;" + result.substring(p0 + 1);
+ //p0 = 0; while ((p0 = result.indexOf("*", p0)) >= 0) result = result.substring(0, p0) + "&#149;" + result.substring(p0 + 1);
+ p0 = 0; while ((p0 = result.indexOf("(C)", p0)) >= 0) result = result.substring(0, p0) + "&copy;" + result.substring(p0 + 3);
+
+ return result;
}
- public static String[] htmlentities={
- "&","&amp;", // Ampersands _have_ to be replaced first. If they were replaced later,
- // other replaced characters containing ampersands would get messed up.
- //" ","&nbsp;",
- "�","&iexcl;",
- "�","&cent;",
- "�","&pound;",
- //"?","&curren;",
- "�","&yen;",
- //"?","&brvbar;",
- "�","&sect;",
- //"?","&uml;",
- "�","&copy;",
- "�","&ordf;",
- "�","&laquo;",
- "�","&not;",
- //"","&shy;",
- "�","&reg;",
- "�","&macr;",
- "�","&deg;",
- "�","&plusmn;",
- "�","&sup2;",
- "�","&sup3;",
- //"?","&acute;",
- "�","&micro;",
- "�","&para;",
- "�","&middot;",
- //"?","&cedil;",
- "�","&sup1;",
- "�","&ordm;",
- "�","&raquo;",
- //"?","&frac14;",
- //"?","&frac12;",
- //"?","&frac34;",
- "�","&iquest;",
- "�","&Agrave;",
- "�","&Aacute;",
- "�","&Acirc;",
- "�","&Atilde;",
- "�","&Auml;",
- "�","&Aring;",
- "�","&AElig;",
- "�","&Ccedil;",
- "�","&Egrave;",
- "�","&Eacute;",
- "�","&Ecirc;",
- "�","&Euml;",
- "�","&Igrave;",
- "�","&Iacute;",
- "�","&Icirc;",
- "�","&Iuml;",
- "�","&ETH;",
- "�","&Ntilde;",
- "�","&Ograve;",
- "�","&Oacute;",
- "�","&Ocirc;",
- "�","&Otilde;",
- "�","&Ouml;",
- "�","&times;",
- "�","&Oslash;",
- "�","&Ugrave;",
- "�","&Uacute;",
- "�","&Ucirc;",
- "�","&Uuml;",
- "�","&Yacute;",
- "�","&THORN;",
- "�","&szlig;",
- "�","&agrave;",
- "�","&aacute;",
- "�","&acirc;",
- "�","&atilde;",
- "�","&auml;",
- "�","&aring;",
- "�","&aelig;",
- "�","&ccedil;",
- "�","&egrave;",
- "�","&eacute;",
- "�","&ecirc;",
- "�","&euml;",
- "�","&igrave;",
- "�","&iacute;",
- "�","&icirc;",
- "�","&iuml;",
- "�","&eth;",
- "�","&ntilde;",
- "�","&ograve;",
- "�","&oacute;",
- "�","&ocirc;",
- "�","&otilde;",
- "�","&ouml;",
- "�","&divide;",
- "�","&oslash;",
- "�","&ugrave;",
- "�","&uacute;",
- "�","&ucirc;",
- "�","&uuml;",
- "�","&yacute;",
- "�","&thorn;",
- "�","&yuml;",
- "\"","&quot;",
- "<","&lt;",
- ">","&gt;",
- "(C)","&copy;"
- };
- //end of Kane's code
-
/** Replaces wiki tags with HTML tags.
*
* @param result a line of text