abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r613214 - /incubator/abdera/java/trunk/extensions/html/src/main/java/org/apache/abdera/ext/html/HtmlCleaner.java
Date Fri, 18 Jan 2008 17:42:09 GMT
Author: jmsnell
Date: Fri Jan 18 09:41:59 2008
New Revision: 613214

URL: http://svn.apache.org/viewvc?rev=613214&view=rev
Log:
Need to check for <, > and & in character data and escape it manually

Modified:
    incubator/abdera/java/trunk/extensions/html/src/main/java/org/apache/abdera/ext/html/HtmlCleaner.java

Modified: incubator/abdera/java/trunk/extensions/html/src/main/java/org/apache/abdera/ext/html/HtmlCleaner.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/html/src/main/java/org/apache/abdera/ext/html/HtmlCleaner.java?rev=613214&r1=613213&r2=613214&view=diff
==============================================================================
--- incubator/abdera/java/trunk/extensions/html/src/main/java/org/apache/abdera/ext/html/HtmlCleaner.java
(original)
+++ incubator/abdera/java/trunk/extensions/html/src/main/java/org/apache/abdera/ext/html/HtmlCleaner.java
Fri Jan 18 09:41:59 2008
@@ -106,6 +106,39 @@
         }
       } 
       super.endElement(uri, localName, name);
+    }
+    
+    @Override 
+    public void characters(
+      char[] ch, 
+      int start, 
+      int length)
+        throws SAXException {
+      StringBuilder buf = new StringBuilder();
+      for (int n = start; n < (start + length); n++) {
+        if (ch[n] == '<') buf.append("&lt;");
+        else if (ch[n] == '>') buf.append("&gt;");
+        else if (ch[n] == '&') {
+          boolean isentity = false;
+          int i = n;
+          String ent = null;
+          for (; i < (start+length); i++) {
+            if (ch[i] == ';') {
+              ent = new String(ch,n,i-n+1);
+              isentity = ent.matches("\\&[\\w]*\\;");
+              break;
+            }
+          }
+          if (isentity) {
+            buf.append(ent);
+            n = i;
+          } else {
+            buf.append("&amp;");
+          }
+        }
+        else buf.append(ch[n]);
+      }
+      super.characters(buf.toString().toCharArray(), 0, buf.length());
     }    
   }
 }



Mime
View raw message