Escape ASCII NUL before trying to put it in XML, because XML can't cope.
Our sholes continuous build is having XML trouble with a FormatterTest
failure that outputs ASCII NUL. Ideally, our junit test runner would escape
all non-printable ASCII as \u escapes, but this seems like a minimal change,
and it's one we already have in the equivalent jtreg code.
Change-Id: Ib9b3219c25515fb358c204d45cb5064293a85b9f
diff --git a/luni/src/test/java/com/google/coretests/XmlReportPrinter.java b/luni/src/test/java/com/google/coretests/XmlReportPrinter.java
index edd9a12..f098b3a 100644
--- a/luni/src/test/java/com/google/coretests/XmlReportPrinter.java
+++ b/luni/src/test/java/com/google/coretests/XmlReportPrinter.java
@@ -225,7 +225,7 @@
serializer.attribute(ns, ATTR_MESSAGE, t.getMessage());
}
serializer.attribute(ns, ATTR_TYPE, t.getClass().getName());
- serializer.text(BaseTestRunner.getFilteredTrace(t));
+ serializer.text(sanitize(BaseTestRunner.getFilteredTrace(t)));
serializer.endTag(ns, type);
serializer.endTag(ns, TESTCASE);
@@ -246,5 +246,12 @@
@Override public int hashCode() {
return name.hashCode() ^ className.hashCode();
}
+
+ /**
+ * Returns the text in a format that is safe for use in an XML document.
+ */
+ private static String sanitize(String text) {
+ return text.replace("\0", "<\\0>");
+ }
}
}