maven-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] abaxanean closed pull request #180: SUREFIRE-1454 fix for empty array
Date Wed, 11 Apr 2018 21:54:38 GMT
abaxanean closed pull request #180: SUREFIRE-1454 fix for empty array
URL: https://github.com/apache/maven-surefire/pull/180
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/util/internal/StringUtils.java
b/surefire-api/src/main/java/org/apache/maven/surefire/util/internal/StringUtils.java
index 23d372c75..b0665bd1e 100644
--- a/surefire-api/src/main/java/org/apache/maven/surefire/util/internal/StringUtils.java
+++ b/surefire-api/src/main/java/org/apache/maven/surefire/util/internal/StringUtils.java
@@ -239,6 +239,10 @@ else if ( ch >= 'A' )
     public static EncodedArray escapeBytesToPrintable( final byte[] header, final byte[]
input, final int off,
                                                        final int len )
     {
+        if ( input.length == 0 )
+        {
+            return EncodedArray.EMPTY;
+        }
         if ( off < 0 || len < 0 || off >= input.length || len > input.length
|| off > len )
         {
             throw new IndexOutOfBoundsException(
@@ -359,6 +363,8 @@ public static boolean startsWith( StringBuffer buffer, String pattern
)
      */
     public static final class EncodedArray
     {
+        private static final EncodedArray EMPTY = new EncodedArray( new byte[]{}, 0 );
+
         private final byte[] array;
         private final int size;
 
diff --git a/surefire-api/src/test/java/org/apache/maven/surefire/util/internal/StringUtilsTest.java
b/surefire-api/src/test/java/org/apache/maven/surefire/util/internal/StringUtilsTest.java
index dea6c9b1a..96e5ed31a 100644
--- a/surefire-api/src/test/java/org/apache/maven/surefire/util/internal/StringUtilsTest.java
+++ b/surefire-api/src/test/java/org/apache/maven/surefire/util/internal/StringUtilsTest.java
@@ -110,4 +110,13 @@ public void testEscapeWithHeader()
 
         assertArrayEquals( expectedResult, actualResult );
     }
+
+    public void testEmptyByteArray()
+    {
+        byte[] header = { (byte) 'a' };
+        byte[] input = {};
+        EncodedArray encodedArray = StringUtils.escapeBytesToPrintable( header, input, 0,
input.length );
+        assertEquals( 0, encodedArray.getSize() );
+        assertEquals( 0, encodedArray.getArray().length );
+    }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message