Updated Branches: refs/heads/master 54395d060 -> ce62b9a2c
[SUREFIRE-996] <system-out> and <system-err> content of junit xml report are not escaped Testcase by Julien Vermillard. Fix by me. Testcase extended by me. Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/ce62b9a2 Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/ce62b9a2 Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/ce62b9a2 Branch: refs/heads/master Commit: ce62b9a2c0b36105355f44c71f29f01d2f818c46 Parents: 54395d0 Author: Kristian Rosenvold <krosenv...@apache.org> Authored: Tue May 28 19:11:26 2013 +0200 Committer: Kristian Rosenvold <krosenv...@apache.org> Committed: Tue May 28 19:18:31 2013 +0200 ---------------------------------------------------------------------- .../surefire/report/StatelessXmlReporter.java | 40 +++++++++++--- .../surefire/report/StatelessXMLReporterTest.java | 10 ++-- 2 files changed, 36 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/ce62b9a2/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java index 0c97101..b1ced5e 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java @@ -19,24 +19,23 @@ package org.apache.maven.plugin.surefire.report; * under the License. */ +import org.apache.commons.io.output.DeferredFileOutputStream; +import org.apache.maven.shared.utils.io.IOUtil; +import org.apache.maven.shared.utils.xml.XMLWriter; +import org.apache.maven.surefire.report.ReportEntry; +import org.apache.maven.surefire.report.ReporterException; +import org.apache.maven.surefire.report.SafeThrowable; + import java.io.File; import java.io.FileOutputStream; import java.io.FilterOutputStream; import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; -import java.io.Writer; import java.util.Enumeration; import java.util.Properties; import java.util.StringTokenizer; -import org.apache.commons.io.output.DeferredFileOutputStream; -import org.apache.maven.shared.utils.io.IOUtil; -import org.apache.maven.shared.utils.xml.XMLWriter; -import org.apache.maven.surefire.report.ReportEntry; -import org.apache.maven.surefire.report.ReporterException; -import org.apache.maven.surefire.report.SafeThrowable; - import static org.apache.maven.plugin.surefire.report.FileReporterUtils.stripIllegalFilenameChars; /** @@ -277,7 +276,8 @@ public class StatelessXmlReporter ppw.endElement(); // test element } - private void addOutputStreamElement( OutputStreamWriter outputStreamWriter, OutputStream fw, EncodingOutputStream eos, XMLWriter xmlWriter, DeferredFileOutputStream stdOut, + private void addOutputStreamElement( OutputStreamWriter outputStreamWriter, OutputStream fw, + EncodingOutputStream eos, XMLWriter xmlWriter, DeferredFileOutputStream stdOut, String name ) { if ( stdOut != null && stdOut.getByteCount() > 0 ) @@ -382,6 +382,28 @@ public class StatelessXmlReporter out.write( b ); out.write( ';' ); // & Will be encoded to amp inside xml encodingSHO } + else if ( '<' == b ) + { + out.write( '&' ); + out.write( 'l' ); + out.write( 't' ); + out.write( ';' ); // & Will be encoded to amp inside xml encodingSHO + } + else if ( '>' == b ) + { + out.write( '&' ); + out.write( 'g' ); + out.write( 't' ); + out.write( ';' ); // & Will be encoded to amp inside xml encodingSHO + } + else if ( '&' == b ) + { + out.write( '&' ); + out.write( 'a' ); + out.write( 'm' ); + out.write( 'p' ); + out.write( ';' ); // & Will be encoded to amp inside xml encodingSHO + } else { out.write( b ); //To change body of overridden methods use File | Settings | File Templates. http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/ce62b9a2/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/StatelessXMLReporterTest.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/StatelessXMLReporterTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/StatelessXMLReporterTest.java index dc18b45..3aa62fc 100644 --- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/StatelessXMLReporterTest.java +++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/StatelessXMLReporterTest.java @@ -87,9 +87,9 @@ public class StatelessXMLReporterTest stats.testSucceeded( testSetReportEntry ); StackTraceWriter stackTraceWriter = new DeserializedStacktraceWriter( "A fud msg", "trimmed", "fail at foo" ); DeferredFileOutputStream s = new DeferredFileOutputStream( 1000000, "fds", "fdx", new File( "" ) ); - s.write( "std-out!".getBytes() ); + s.write( "std-out<null>!".getBytes() ); DeferredFileOutputStream s1 = new DeferredFileOutputStream( 1000000, "fds", "fdx", new File( "" ) ); - s1.write( "std-err?".getBytes() ); + s1.write( "std-err?&-&£".getBytes() ); WrappedReportEntry t2 = new WrappedReportEntry( new SimpleReportEntry( Inner.class.getName(), testName2, stackTraceWriter, 13 ), ReportEntryType.error, 13, s, s1 ); @@ -120,8 +120,8 @@ public class StatelessXMLReporterTest assertNotNull( errorNode ); assertEquals( "A fud msg", errorNode.getAttribute( "message" ) ); assertEquals( "fail at foo", errorNode.getAttribute( "type" ) ); - assertEquals( "std-out!", tcb.getChild( "system-out" ).getValue() ); - assertEquals( "std-err?", tcb.getChild( "system-err" ).getValue() ); + assertEquals( "std-out<null>!", tcb.getChild( "system-out" ).getValue() ); + assertEquals( "std-err?&-&£", tcb.getChild( "system-err" ).getValue() ); expectedReportFile.delete(); } @@ -131,4 +131,4 @@ public class StatelessXMLReporterTest } -} \ No newline at end of file +}