xml-rpc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adam Megacz <a...@megacz.com>
Subject org.apache.xmlrpc.XmlWriter emits invalid XML
Date Sun, 18 Aug 2002 00:54:46 GMT

According to XML 1.0, a CDATA section may contain only:

  [2] Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] |
               [#x10000-#x10FFFF]

  http://www.w3.org/TR/2000/REC-xml-20001006#charsets

XmlWriter fails to &#XXXX;-encode characters below 0x20, and emits XML
which is unparseable by most XML parsers.

The following patch fixes this bug.

  - a


Index: src/java/org/apache/xmlrpc/XmlWriter.java
===================================================================
RCS file: /home/cvspublic/xml-rpc/src/java/org/apache/xmlrpc/XmlWriter.java,v
retrieving revision 1.2
diff -u -r1.2 XmlWriter.java
--- src/java/org/apache/xmlrpc/XmlWriter.java	8 Aug 2002 21:31:50 -0000	1.2
+++ src/java/org/apache/xmlrpc/XmlWriter.java	18 Aug 2002 00:51:13 -0000
@@ -305,6 +305,11 @@
             char c = text.charAt (i);
             switch (c)
             {
+            case '\t':
+            case '\r':
+            case '\n':
+                write(c);
+                break;
             case '<':
                 write(LESS_THAN_ENTITY);
                 break;
@@ -315,7 +320,13 @@
                 write(AMPERSAND_ENTITY);
                 break;
             default:
-                write(c);
+                if (c < 0x20 || c > 0xff) {
+                    write("&#");
+                    write(String.valueOf((int)c));
+                    write(";");
+                } else {
+                    write(c);
+                }
             }
         }
     }

Mime
View raw message