OSDN Git Service

Sanitize text before emitting to XML.
authorJesse Wilson <jessewilson@google.com>
Fri, 6 Nov 2009 19:41:32 +0000 (11:41 -0800)
committerJesse Wilson <jessewilson@google.com>
Fri, 6 Nov 2009 19:41:32 +0000 (11:41 -0800)
This is the absolute least amount of sanitization that will work.
I'll consider adding more as necessary; currently I'm not too
interested in spending the time to make this perfect.

libcore/tools/dalvik_jtreg/java/dalvik/jtreg/XmlReportPrinter.java

index bc3c507..bfea0bc 100644 (file)
@@ -187,11 +187,19 @@ public class XmlReportPrinter {
                     serializer.attribute(ns, ATTR_MESSAGE, title);
                 }
                 serializer.attribute(ns, ATTR_TYPE, testRun.getResult().toString());
-                serializer.text(Strings.join(testRun.getOutputLines(), "\n"));
+                String text = sanitize(Strings.join(testRun.getOutputLines(), "\n"));
+                serializer.text(text);
                 serializer.endTag(ns, result);
             }
 
             serializer.endTag(ns, TESTCASE);
         }
+
+        /**
+         * Returns the text in a format that is safe for use in an XML document.
+         */
+        private String sanitize(String text) {
+            return text.replace("\0", "<\\0>");
+        }
     }
 }
\ No newline at end of file