Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.4, 2.4.1
-
None
-
Patch
Description
XML delimiter characters (left angle bracket, ampersand, etc.) are escaped twice in TEST-*.xml files in surefire-reports directory. For example the left angle bracket is replaced with < instead of < and the right angle bracket with > instead of >
<testcase time="2.306" classname="MyTest" name="testItem"> <failure message="expected:&lt;10&gt; but was:&lt;7&gt;" type="junit.framework.AssertionFailedError"> junit.framework.AssertionFailedError: expected:&lt;10&gt; but was:&lt;7&gt; at junit.framework.Assert.fail(Assert.java:47) at junit.framework.Assert.failNotSame(Assert.java:278) at junit.framework.Assert.assertSame(Assert.java:242) at MyTest.testItem(MyTest.java:38) </failure> </testcase>
The problem is that both org.apache.maven.surefire.report.XMLReporter and org.apache.maven.surefire.util.PrettyPrintXMLWriter are escaping the XML content. As a result the ampersand character is escaped once more time. In addition org.apache.maven.surefire.util.PrettyPrintXMLWriter#escapeXml has implementation error: three characters (ampersand, left angle bracket and right angle bracket) are replaced with &
In the attached patch (for surefire-2.4.1) I removed org.apache.maven.surefire.report.XMLReporter#escapeAttribute method and fixed org.apache.maven.surefire.util.PrettyPrintXMLWriter#escapeXml implementation. Afterwards the XML report was generated as expected:
<testcase time="2.306" classname="MyTest" name="testItem"> <failure message="expected:<10> but was:<7>" type="junit.framework.AssertionFailedError"> junit.framework.AssertionFailedError: expected:<10> but was:<7> at junit.framework.Assert.fail(Assert.java:47) at junit.framework.Assert.failNotSame(Assert.java:278) at junit.framework.Assert.assertSame(Assert.java:242) at MyTest.testItem(MyTest.java:38) </failure> </testcase>