You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ag...@apache.org on 2013/08/09 22:44:25 UTC

[1/2] git commit: [SUREFIRE-1020] Fix rewriting of chars in system-out and system-err that are illegal in XML 1.0/1.1

Updated Branches:
  refs/heads/master 49c4a6259 -> a78ce4ce4


[SUREFIRE-1020] Fix rewriting of chars in system-out and system-err that are illegal in XML 1.0/1.1


Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/1420d7f5
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/1420d7f5
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/1420d7f5

Branch: refs/heads/master
Commit: 1420d7f57481f18fde4d407dfb8665f5dd21b424
Parents: 49c4a62
Author: Andreas Gudian <ag...@apache.org>
Authored: Fri Aug 9 22:41:44 2013 +0200
Committer: Andreas Gudian <ag...@apache.org>
Committed: Fri Aug 9 22:41:44 2013 +0200

----------------------------------------------------------------------
 .../surefire/report/StatelessXmlReporter.java   | 47 +++++++++++++++-----
 1 file changed, 35 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/1420d7f5/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 a7e61b9..b1fc83b 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
@@ -32,6 +32,7 @@ import java.io.FilterOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
+import java.io.UnsupportedEncodingException;
 import java.util.Enumeration;
 import java.util.Properties;
 import java.util.StringTokenizer;
@@ -73,7 +74,7 @@ import static org.apache.maven.plugin.surefire.report.FileReporterUtils.stripIll
 public class StatelessXmlReporter
 {
 
-    private static final byte[] ampBytes = "&amp#".getBytes();
+    private static final String ENCODING = "UTF-8";
 
     private final File reportsDirectory;
 
@@ -81,7 +82,6 @@ public class StatelessXmlReporter
 
     private final boolean trimStackTrace;
 
-    private final String encoding = "UTF-8";
 
     public StatelessXmlReporter( File reportsDirectory, String reportNameSuffix, boolean trimStackTrace )
     {
@@ -101,7 +101,7 @@ public class StatelessXmlReporter
 
             org.apache.maven.shared.utils.xml.XMLWriter ppw =
                 new org.apache.maven.shared.utils.xml.PrettyPrintXMLWriter( fw );
-            ppw.setEncoding( encoding );
+            ppw.setEncoding( ENCODING );
 
             createTestSuiteElement( ppw, testSetReportEntry, testSetStats, reportNameSuffix );
 
@@ -134,7 +134,7 @@ public class StatelessXmlReporter
         try
         {
 
-            return new OutputStreamWriter( fos, encoding );
+            return new OutputStreamWriter( fos, ENCODING );
         }
         catch ( IOException e )
         {
@@ -290,9 +290,9 @@ public class StatelessXmlReporter
                 xmlWriter.writeText( "" ); // Cheat sax to emit element
                 outputStreamWriter.flush();
                 stdOut.close();
-                eos.getUnderlying().write( "<![CDATA[".getBytes() ); // emit cdata
+                eos.getUnderlying().write( ByteConstantsHolder.CDATA_START_BYTES ); // emit cdata
                 stdOut.writeTo( eos );
-                eos.getUnderlying().write( "]]>".getBytes() );
+                eos.getUnderlying().write( ByteConstantsHolder.CDATA_END_BYTES );
                 eos.flush();
             }
             catch ( IOException e )
@@ -367,8 +367,6 @@ public class StatelessXmlReporter
 
         private int c2;
 
-        private static final byte[] cdataEscapeString = "]]><![CDATA[>".getBytes();
-
         public EncodingOutputStream( OutputStream out )
         {
             super( out );
@@ -390,7 +388,7 @@ public class StatelessXmlReporter
         {
             if ( isCdataEndBlock( b ) )
             {
-                out.write( cdataEscapeString );
+                out.write( ByteConstantsHolder.CDATA_ESCAPE_STRING_BYTES );
             }
             else if ( isIllegalEscape( b ) )
             {
@@ -399,8 +397,8 @@ public class StatelessXmlReporter
                 // we're going to deliberately doubly-XML escape it...
                 // there's nothing better we can do! :-(
                 // SUREFIRE-456
-                out.write( ampBytes );
-                out.write( b );
+                out.write( ByteConstantsHolder.AMP_BYTES );
+                out.write( String.valueOf( b ).getBytes( ENCODING ) );
                 out.write( ';' ); // & Will be encoded to amp inside xml encodingSHO
             }
             else
@@ -428,7 +426,7 @@ public class StatelessXmlReporter
 
     private static boolean isIllegalEscape( char c )
     {
-        return c >= 0 && c < 32 && c != '\n' && c != '\r' && c != '\t';
+        return isIllegalEscape( (int) c );
     }
 
     private static boolean isIllegalEscape( int c )
@@ -460,4 +458,29 @@ public class StatelessXmlReporter
         return sb.toString();
     }
 
+    private static class ByteConstantsHolder
+    {
+        private static final byte[] CDATA_START_BYTES;
+
+        private static final byte[] CDATA_END_BYTES;
+
+        private static final byte[] CDATA_ESCAPE_STRING_BYTES;
+
+        private static final byte[] AMP_BYTES;
+
+        static
+        {
+            try
+            {
+                CDATA_START_BYTES = "<![CDATA[".getBytes( ENCODING );
+                CDATA_END_BYTES = "]]>".getBytes( ENCODING );
+                CDATA_ESCAPE_STRING_BYTES = "]]><![CDATA[>".getBytes( ENCODING );
+                AMP_BYTES = "&amp#".getBytes( ENCODING );
+            }
+            catch ( UnsupportedEncodingException e )
+            {
+                throw new RuntimeException( e );
+            }
+        }
+    }
 }


[2/2] git commit: [SUREFIRE-1020] Extended unit test Submitted by: Todor Todorov

Posted by ag...@apache.org.
[SUREFIRE-1020] Extended unit test
Submitted by: Todor Todorov

o Applied without any changes


Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/a78ce4ce
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/a78ce4ce
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/a78ce4ce

Branch: refs/heads/master
Commit: a78ce4ce4b23def58f6894f4ac9ba338611e68bf
Parents: 1420d7f
Author: Andreas Gudian <ag...@apache.org>
Authored: Fri Aug 9 22:43:55 2013 +0200
Committer: Andreas Gudian <ag...@apache.org>
Committed: Fri Aug 9 22:43:55 2013 +0200

----------------------------------------------------------------------
 .../plugin/surefire/report/StatelessXMLReporterTest.java     | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/a78ce4ce/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 9c55898..a99b749 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
@@ -89,10 +89,10 @@ 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( "" ) );
-        String expected = "st]]>d-o\u00DCt<null>!";
+        String expected = "st]]>d-o\u00DCt<null>!\u0020\u0000\u001F";
         s.write( expected.getBytes( "UTF-8" ) );
         DeferredFileOutputStream s1 = new DeferredFileOutputStream( 1000000, "fds", "fdx", new File( "" ) );
-        byte[] bytes = "std-\u0115rr?&-&amp;&#163;".getBytes("UTF-8");
+        byte[] bytes = "std-\u0115rr?&-&amp;&#163;\u0020\u0000\u001F".getBytes("UTF-8");
         s1.write( bytes );
         WrappedReportEntry t2 =
             new WrappedReportEntry( new SimpleReportEntry( Inner.class.getName(), testName2, stackTraceWriter, 13 ),
@@ -126,8 +126,8 @@ public class StatelessXMLReporterTest
         assertNotNull( errorNode );
         assertEquals( "A fud msg", errorNode.getAttribute( "message" ) );
         assertEquals( "fail at foo", errorNode.getAttribute( "type" ) );
-        assertEquals( expected, tcb.getChild( "system-out" ).getValue() );
-        assertEquals( "std-\u0115rr?&-&amp;&#163;", tcb.getChild( "system-err" ).getValue() );
+        assertEquals( "st]]>d-o\u00DCt<null>! &amp#0;&amp#31;", tcb.getChild( "system-out" ).getValue() );
+        assertEquals( "std-\u0115rr?&-&amp;&#163; &amp#0;&amp#31;", tcb.getChild( "system-err" ).getValue() );
 
         expectedReportFile.delete();
     }