Snap for 6680390 from 6a85ad2bf698225d31732a343341c1787e30b451 to rvc-release
Change-Id: I983406ca2c07822d326dab14872b624bc1f6bd9b
diff --git a/src/com/android/tradefed/result/suite/XmlSuiteResultFormatter.java b/src/com/android/tradefed/result/suite/XmlSuiteResultFormatter.java
index 06592b2..772075b 100644
--- a/src/com/android/tradefed/result/suite/XmlSuiteResultFormatter.java
+++ b/src/com/android/tradefed/result/suite/XmlSuiteResultFormatter.java
@@ -34,6 +34,7 @@
import com.android.tradefed.util.proto.TfMetricProtoUtil;
import com.google.common.base.Strings;
+import com.google.common.xml.XmlEscapers;
import com.google.gson.Gson;
import org.xmlpull.v1.XmlPullParser;
@@ -707,7 +708,6 @@
@VisibleForTesting
static String sanitizeXmlContent(String s) {
- // Replace c++ \0 null since Serializer doesn't handle it.
- return s.replace("\0", "[Null]");
+ return XmlEscapers.xmlContentEscaper().escape(s);
}
}
diff --git a/tests/src/com/android/tradefed/result/suite/XmlSuiteResultFormatterTest.java b/tests/src/com/android/tradefed/result/suite/XmlSuiteResultFormatterTest.java
index 67a623a..647db0b 100644
--- a/tests/src/com/android/tradefed/result/suite/XmlSuiteResultFormatterTest.java
+++ b/tests/src/com/android/tradefed/result/suite/XmlSuiteResultFormatterTest.java
@@ -170,7 +170,7 @@
assertXmlContainsValue(
content,
"Result/Module/TestCase/Test/Failure/StackTrace",
- "module1 failed.\nstack\n<null>stack[Null]");
+ XmlSuiteResultFormatter.sanitizeXmlContent("module1 failed.\nstack\nstack\0"));
// Test that we can read back the informations
SuiteResultHolder holder = mFormatter.parseResults(mResultDir, false);
assertEquals(holder.completeModules, mResultHolder.completeModules);
@@ -224,7 +224,7 @@
assertXmlContainsValue(
content,
"Result/Module/TestCase/Test/Failure/StackTrace",
- "module1 failed.\nstack\n<null>stack[Null]");
+ XmlSuiteResultFormatter.sanitizeXmlContent("module1 failed.\nstack\nstack\0"));
// Test that we can read back the informations
SuiteResultHolder holder = mFormatter.parseResults(mResultDir, false);
assertEquals(holder.completeModules, mResultHolder.completeModules);
@@ -477,7 +477,7 @@
assertXmlContainsValue(
content,
"Result/Module/TestCase/Test/Failure/StackTrace",
- "module1 failed.\nstack\n<null>stack[Null]");
+ XmlSuiteResultFormatter.sanitizeXmlContent("module1 failed.\nstack\nstack\0"));
// Test that we can read back the informations
SuiteResultHolder holder = mFormatter.parseResults(mResultDir, true);
assertEquals(holder.completeModules, mResultHolder.completeModules);
@@ -671,7 +671,7 @@
new TestDescription("com.class." + runName, runName + ".failed" + i);
fakeRes.testStarted(description);
// Include a null character \0 that is not XML supported
- fakeRes.testFailed(description, runName + " failed.\nstack\n<null>stack\0");
+ fakeRes.testFailed(description, runName + " failed.\nstack\nstack\0");
HashMap<String, Metric> metrics = new HashMap<String, Metric>();
if (withMetrics) {
metrics.put("metric0" + i, TfMetricProtoUtil.stringToMetric("value0" + i));