You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ti...@apache.org on 2019/04/08 02:30:16 UTC

[maven-surefire] branch SUREFIRE-1617 updated (d893d1b -> f3472a5)

This is an automated email from the ASF dual-hosted git repository.

tibordigana pushed a change to branch SUREFIRE-1617
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git.


 discard d893d1b  [SUREFIRE-1617] Surefire fails with bad message when path contains whitespaces and colon
     new f3472a5  [SUREFIRE-1617] Surefire fails with bad message when path contains whitespaces and colon

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (d893d1b)
            \
             N -- N -- N   refs/heads/SUREFIRE-1617 (f3472a5)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../maven/plugin/surefire/booterclient/JarManifestForkConfiguration.java | 1 -
 1 file changed, 1 deletion(-)


[maven-surefire] 01/01: [SUREFIRE-1617] Surefire fails with bad message when path contains whitespaces and colon

Posted by ti...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

tibordigana pushed a commit to branch SUREFIRE-1617
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git

commit f3472a5396705bf062f1200e2dda3e200a135cc8
Author: tibordigana <ti...@apache.org>
AuthorDate: Sun Apr 7 23:06:45 2019 +0200

    [SUREFIRE-1617] Surefire fails with bad message when path contains whitespaces and colon
---
 .../booterclient/JarManifestForkConfiguration.java | 33 ++++++++++++++++++-
 .../JarManifestForkConfigurationTest.java          | 38 ++++++++++++++++++++--
 2 files changed, 68 insertions(+), 3 deletions(-)

diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/JarManifestForkConfiguration.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/JarManifestForkConfiguration.java
index 62fa4c1..b9fcf8e 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/JarManifestForkConfiguration.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/JarManifestForkConfiguration.java
@@ -31,8 +31,10 @@ import javax.annotation.Nullable;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.UnsupportedEncodingException;
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.net.URLEncoder;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.Iterator;
@@ -215,8 +217,37 @@ public final class JarManifestForkConfiguration
 
         ClasspathElementUri( URI uri )
         {
-            this.uri = uri.toASCIIString();
+            this.uri = escapeUri( uri.toASCIIString() );
             absolute = false;
         }
     }
+
+    static String escapeUri( String input )
+    {
+        StringBuilder b = new StringBuilder( input.length() );
+        for ( int i = 0; i < input.length(); i++ )
+        {
+            char c = input.charAt( i );
+            if ( c == ' ' )
+            {
+                b.append( "%20" );
+            }
+            else if ( c == '%' || c == '/' || c == '\\' )
+            {
+                b.append( c );
+            }
+            else
+            {
+                try
+                {
+                    b.append( URLEncoder.encode( String.valueOf( c ), "UTF-8" ) );
+                }
+                catch ( UnsupportedEncodingException e )
+                {
+                    b.append( c );
+                }
+            }
+        }
+        return b.toString();
+    }
 }
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/JarManifestForkConfigurationTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/JarManifestForkConfigurationTest.java
index 5e71238..7f9dbd9 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/JarManifestForkConfigurationTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/JarManifestForkConfigurationTest.java
@@ -30,6 +30,7 @@ import org.apache.maven.plugin.surefire.booterclient.output.InPluginProcessDumpS
 import static org.apache.maven.plugin.surefire.booterclient.JarManifestForkConfiguration.relativize;
 import static org.apache.maven.plugin.surefire.booterclient.JarManifestForkConfiguration.toAbsoluteUri;
 import static org.apache.maven.plugin.surefire.booterclient.JarManifestForkConfiguration.toClasspathElementUri;
+import static org.apache.maven.plugin.surefire.booterclient.JarManifestForkConfiguration.escapeUri;
 import static org.fest.assertions.Assertions.assertThat;
 
 import org.junit.AfterClass;
@@ -40,6 +41,7 @@ import org.junit.runner.RunWith;
 import static org.fest.util.Files.delete;
 import static org.fest.util.Files.newTemporaryFolder;
 import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.ArgumentMatchers.same;
 import static org.powermock.api.mockito.PowerMockito.mock;
 import static org.powermock.api.mockito.PowerMockito.mockStatic;
@@ -88,6 +90,8 @@ public class JarManifestForkConfigurationTest
                 .thenReturn( "../../../.m2/repository/grp/art/1.0/art-1.0.jar" );
         when( toClasspathElementUri( same( parent ), same( classPathElement ), same( dumpDirectory ), anyBoolean() ) )
                 .thenCallRealMethod();
+        when( escapeUri( anyString() ) )
+                .thenCallRealMethod();
         assertThat( toClasspathElementUri( parent, classPathElement, dumpDirectory, true ).uri )
                 .isEqualTo( "../../../.m2/repository/grp/art/1.0/art-1.0.jar" );
     }
@@ -105,6 +109,8 @@ public class JarManifestForkConfigurationTest
                 .thenReturn( "../../../../../the Maven repo/grp/art/1.0/art-1.0.jar" );
         when( toClasspathElementUri( same( parent ), same( classPathElement ), same( dumpDirectory ), anyBoolean() ) )
                 .thenCallRealMethod();
+        when( escapeUri( anyString() ) )
+                .thenCallRealMethod();
         assertThat( toClasspathElementUri( parent, classPathElement, dumpDirectory, true ).uri )
                 .isEqualTo( "../../../../../the%20Maven%20repo/grp/art/1.0/art-1.0.jar" );
     }
@@ -122,6 +128,8 @@ public class JarManifestForkConfigurationTest
                 .thenReturn( "..\\..\\..\\Users\\me\\.m2\\repository\\grp\\art\\1.0\\art-1.0.jar" );
         when( toClasspathElementUri( same( parent ), same( classPathElement ), same( dumpDirectory ), anyBoolean() ) )
                 .thenCallRealMethod();
+        when( escapeUri( anyString() ) )
+                .thenCallRealMethod();
         assertThat( toClasspathElementUri( parent, classPathElement, dumpDirectory, true ).uri )
                 .isEqualTo( "../../../Users/me/.m2/repository/grp/art/1.0/art-1.0.jar" );
     }
@@ -134,11 +142,14 @@ public class JarManifestForkConfigurationTest
         Path parent = mock( Path.class );
         when( parent.toString() ).thenReturn( "C:\\Windows\\Temp\\surefire" );
         Path classPathElement = mock( Path.class );
-        when( classPathElement.toString() ).thenReturn( "C:\\Test User\\me\\.m2\\repository\\grp\\art\\1.0\\art-1.0.jar" );
+        when( classPathElement.toString() )
+                .thenReturn("C:\\Test User\\me\\.m2\\repository\\grp\\art\\1.0\\art-1.0.jar");
         when( relativize( parent, classPathElement ) )
                 .thenReturn( "..\\..\\..\\Test User\\me\\.m2\\repository\\grp\\art\\1.0\\art-1.0.jar" );
         when( toClasspathElementUri( same( parent ), same( classPathElement ), same( dumpDirectory ), anyBoolean() ) )
                 .thenCallRealMethod();
+        when( escapeUri( anyString() ) )
+                .thenCallRealMethod();
         assertThat( toClasspathElementUri( parent, classPathElement, dumpDirectory, true ).uri )
                 .isEqualTo( "../../../Test%20User/me/.m2/repository/grp/art/1.0/art-1.0.jar" );
     }
@@ -168,6 +179,8 @@ public class JarManifestForkConfigurationTest
                 .thenThrow( new IllegalArgumentException() );
         when( toClasspathElementUri( same( parent ), same( classPathElement ), same( dumpDirectory ), anyBoolean() ) )
                 .thenCallRealMethod();
+        when( escapeUri( anyString() ) )
+                .thenCallRealMethod();
         when( toAbsoluteUri( same( classPathElement ) ) )
                 .thenCallRealMethod();
         assertThat( toClasspathElementUri( parent, classPathElement, dumpDirectory, true ).uri )
@@ -175,6 +188,27 @@ public class JarManifestForkConfigurationTest
     }
 
     @Test
+    public void shouldEscapeUri()
+    {
+        assertThat( JarManifestForkConfiguration.escapeUri( "a" ) ).isEqualTo( "a" );
+        assertThat( JarManifestForkConfiguration.escapeUri( " " ) ).isEqualTo( "%20" );
+        assertThat( JarManifestForkConfiguration.escapeUri( "%" ) ).isEqualTo( "%" );
+        assertThat( JarManifestForkConfiguration.escapeUri( "," ) ).isEqualTo( "%2C" );
+        assertThat( JarManifestForkConfiguration.escapeUri( "/" ) ).isEqualTo( "/" );
+        assertThat( JarManifestForkConfiguration.escapeUri( "7" ) ).isEqualTo( "7" );
+        assertThat( JarManifestForkConfiguration.escapeUri( ":" ) ).isEqualTo( "%3A" );
+        assertThat( JarManifestForkConfiguration.escapeUri( "@" ) ).isEqualTo( "%40" );
+        assertThat( JarManifestForkConfiguration.escapeUri( "A" ) ).isEqualTo( "A" );
+        assertThat( JarManifestForkConfiguration.escapeUri( "[" ) ).isEqualTo( "%5B" );
+        assertThat( JarManifestForkConfiguration.escapeUri( "\\" ) ).isEqualTo( "\\" );
+        assertThat( JarManifestForkConfiguration.escapeUri( "]" ) ).isEqualTo( "%5D" );
+        assertThat( JarManifestForkConfiguration.escapeUri( "`" ) ).isEqualTo( "%60" );
+        assertThat( JarManifestForkConfiguration.escapeUri( "a" ) ).isEqualTo( "a" );
+        assertThat( JarManifestForkConfiguration.escapeUri( "{" ) ).isEqualTo( "%7B" );
+        assertThat( JarManifestForkConfiguration.escapeUri( "" + (char) 0xFF ) ).isEqualTo( "%C3%BF" );
+    }
+
+    @Test
     public void shouldRelativizeOnRealPlatform()
     {
         Path parentDir = new File( TMP, "test-parent-1" )
@@ -218,6 +252,6 @@ public class JarManifestForkConfigurationTest
         ClasspathElementUri testDirUriPath = toClasspathElementUri( parentDir, testDir, dumpDirectory, true );
 
         assertThat( testDirUriPath.uri )
-                .isEqualTo( "../@3%20test%20with%20white%20spaces" );
+                .isEqualTo( "../%403%20test%20with%20white%20spaces" );
     }
 }