You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2019/10/29 19:14:18 UTC

[maven-wagon] branch WAGON-569 updated (130ac45 -> 7d1315e)

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

michaelo pushed a change to branch WAGON-569
in repository https://gitbox.apache.org/repos/asf/maven-wagon.git.


 discard 130ac45  Split encodeURLToString() in two methods
 discard 3e34ecc  [WAGON-569] Inconsistent encoding behavior for repository URLs with spaces
     new 7d1315e  [WAGON-569] Inconsistent encoding behavior for repository URLs with spaces

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   (130ac45)
            \
             N -- N -- N   refs/heads/WAGON-569 (7d1315e)

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:
 .../apache/maven/wagon/shared/http/EncodingUtilTest.java   | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)


[maven-wagon] 01/01: [WAGON-569] Inconsistent encoding behavior for repository URLs with spaces

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

michaelo pushed a commit to branch WAGON-569
in repository https://gitbox.apache.org/repos/asf/maven-wagon.git

commit 7d1315e47df948d8b17f5c759b20a5b3437cbff7
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Wed Oct 16 22:42:06 2019 +0200

    [WAGON-569] Inconsistent encoding behavior for repository URLs with spaces
---
 .../wagon/shared/http/AbstractHttpClientWagon.java | 18 ++++--
 .../maven/wagon/shared/http/EncodingUtil.java      | 50 ++++++++++------
 .../maven/wagon/shared/http/EncodingUtilTest.java  | 67 +++++++++++++++++++++-
 3 files changed, 113 insertions(+), 22 deletions(-)

diff --git a/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java b/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java
index 9d3630b..09ff0ef 100755
--- a/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java
+++ b/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java
@@ -665,9 +665,19 @@ public abstract class AbstractHttpClientWagon
      */
     private String buildUrl( Resource resource )
     {
-        return EncodingUtil.encodeURLToString( getRepository().getUrl(), resource.getName() );
+        return buildUrl( resource.getName() );
     }
 
+    /**
+     * Builds a complete URL string from the repository URL and the relative path of the resource passed.
+     *
+     * @param resourceName the resourcerelative path
+     * @return the complete URL
+     */
+    private String buildUrl( String resourceName )
+    {
+        return EncodingUtil.encodeURLToString( getRepository().getUrl(), resourceName );
+    }
 
     private void put( Resource resource, File source, HttpEntity httpEntity, String url )
         throws TransferFailedException, AuthorizationException, ResourceDoesNotExistException
@@ -804,8 +814,7 @@ public abstract class AbstractHttpClientWagon
     private boolean resourceExists( int wait, String resourceName )
         throws TransferFailedException, AuthorizationException
     {
-        String repositoryUrl = getRepository().getUrl();
-        String url = repositoryUrl + ( repositoryUrl.endsWith( "/" ) ? "" : "/" ) + resourceName;
+        String url = buildUrl( resourceName );
         HttpHead headMethod = new HttpHead( url );
         try
         {
@@ -1082,8 +1091,7 @@ public abstract class AbstractHttpClientWagon
     {
         Resource resource = inputData.getResource();
 
-        String repositoryUrl = getRepository().getUrl();
-        String url = repositoryUrl + ( repositoryUrl.endsWith( "/" ) ? "" : "/" ) + resource.getName();
+        String url = buildUrl( resource );
         HttpGet getMethod = new HttpGet( url );
         long timestamp = resource.getLastModified();
         if ( timestamp > 0 )
diff --git a/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/EncodingUtil.java b/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/EncodingUtil.java
index 1794288..67f5e5f 100644
--- a/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/EncodingUtil.java
+++ b/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/EncodingUtil.java
@@ -24,6 +24,8 @@ import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
 
+import org.apache.http.client.utils.URLEncodedUtils;
+
 /**
  * Encoding utility.
  *
@@ -38,7 +40,9 @@ public class EncodingUtil
      * @return Parsed/encoded {@link URI} that represents the string form URL passed in.
      * @throws MalformedURLException
      * @throws URISyntaxException
+     * @deprecated to be removed with 4.0.0
      */
+    @Deprecated
     public static URI encodeURL( String url )
         throws MalformedURLException, URISyntaxException
     {
@@ -61,7 +65,9 @@ public class EncodingUtil
      * @param url Raw/decoded string form of a URL to parse/encode.
      * @return Parsed/encoded URI (as string) that represents the
      * @throws IllegalArgumentException in case the URL string is invalid.
+     * @deprecated To be remvoed with 4.0.0
      */
+    @Deprecated
     public static String encodeURLToString( String url )
     {
         try
@@ -75,31 +81,43 @@ public class EncodingUtil
     }
 
     /**
-     * Parses and returns an encoded version of the given URL string alongside the given paths.
+     * Parses and returns an encoded version of the given URL string alongside the given path.
+     *
+     * @param baseUrl Base URL to use when constructing the final URL. This has to be a valid URL already.
+     * @param path Additional unencoded path to append at the end of the base path.
+     * @return Composed URL (base + path) already encoded, separating the individual path segments by "/".
+     * @since TODO
+     */
+    public static String encodeURLToString( String baseUrl, String path )
+    {
+        String[] pathSegments = path == null ? new String[0] : path.split( "/" );
+
+        return encodeURLToString( baseUrl, pathSegments );
+    }
+
+    /**
+     * Parses and returns an encoded version of the given URL string alongside the given path segments.
      *
-     * @param baseUrl Base URL to use when constructing the final URL, ie: scheme://authority/initial.path.
-     * @param paths   Additional path(s) to append at the end of the base path.
-     * @return Composed URL (base + paths) already encoded, separating the individual path components by "/".
+     * @param baseUrl Base URL to use when constructing the final URL. This has to be a valid URL already.
+     * @param pathSegments Additional unencoded path segments to append at the end of the base path.
+     * @return Composed URL (base + path) already encoded, separating the individual path segments by "/".
      * @since TODO
      */
-    public static String encodeURLToString( String baseUrl, String... paths )
+    public static String encodeURLToString( String baseUrl, String... pathSegments )
     {
         StringBuilder url = new StringBuilder( baseUrl );
 
-        String[] parts = paths == null ? //
-            new String[0] : //
-            paths.length == 1 ? paths[0].split( "/" ) : paths;
+        String[] segments = pathSegments == null ? new String[0] : pathSegments;
 
-        for ( String part : parts )
-        {
-            if ( !url.toString().endsWith( "/" ) )
-            {
-                url.append( '/' );
-            }
+        String path = URLEncodedUtils.formatSegments( segments );
 
-            url.append( part );
+        if ( url.toString().endsWith( "/" ) && !path.isEmpty() )
+        {
+            url.deleteCharAt( url.length() - 1 );
         }
 
-        return encodeURLToString( url.toString() );
+        url.append( path );
+
+        return url.toString();
     }
 }
diff --git a/wagon-providers/wagon-http-shared/src/test/java/org/apache/maven/wagon/shared/http/EncodingUtilTest.java b/wagon-providers/wagon-http-shared/src/test/java/org/apache/maven/wagon/shared/http/EncodingUtilTest.java
index f20f35f..4ec549c 100644
--- a/wagon-providers/wagon-http-shared/src/test/java/org/apache/maven/wagon/shared/http/EncodingUtilTest.java
+++ b/wagon-providers/wagon-http-shared/src/test/java/org/apache/maven/wagon/shared/http/EncodingUtilTest.java
@@ -46,8 +46,73 @@ public class EncodingUtilTest
     public void testEncodeURLWithSpacesInBothBaseAndPath()
         throws URISyntaxException, MalformedURLException
     {
-        String encodedURL = EncodingUtil.encodeURLToString( "file://host:1/with a", "path with spaces" );
+        String encodedURL = EncodingUtil.encodeURLToString( "file://host:1/with%20a", "path with spaces" );
 
         assertEquals( "file://host:1/with%20a/path%20with%20spaces", encodedURL );
     }
+
+    public void testEncodeURLWithSlashes1()
+        throws URISyntaxException, MalformedURLException
+    {
+        String encodedURL = EncodingUtil.encodeURLToString( "file://host:1/basePath", "a", "b", "c" );
+
+        assertEquals( "file://host:1/basePath/a/b/c", encodedURL );
+
+        encodedURL = EncodingUtil.encodeURLToString( "file://host:1/basePath", "a/b/c" );
+
+        assertEquals( "file://host:1/basePath/a/b/c", encodedURL );
+    }
+
+    public void testEncodeURLWithSlashes2()
+        throws URISyntaxException, MalformedURLException
+    {
+        String encodedURL = EncodingUtil.encodeURLToString( "file://host:1/basePath/", "a", "b", "c" );
+
+        assertEquals( "file://host:1/basePath/a/b/c", encodedURL );
+
+        encodedURL = EncodingUtil.encodeURLToString( "file://host:1/basePath/", "a/b/c" );
+
+        assertEquals( "file://host:1/basePath/a/b/c", encodedURL );
+    }
+
+    public void testEncodeURLWithSlashes3()
+            throws URISyntaxException, MalformedURLException
+    {
+        String encodedURL = EncodingUtil.encodeURLToString( "file://host:1/basePath/", new String[0] );
+
+        assertEquals( "file://host:1/basePath/", encodedURL );
+    }
+
+    public void testEncodeURLWithSlashes4()
+        throws URISyntaxException, MalformedURLException
+    {
+        String encodedURL = EncodingUtil.encodeURLToString( "file://host:1/basePath", new String[0] );
+
+        assertEquals( "file://host:1/basePath", encodedURL );
+    }
+
+    public void testEncodeURLWithSlashes5()
+        throws URISyntaxException, MalformedURLException
+    {
+        String encodedURL = EncodingUtil.encodeURLToString( "file://host:1/basePath",
+                                                            "a/1", "b/1", "c/1" );
+
+        assertEquals( "file://host:1/basePath/a%2F1/b%2F1/c%2F1", encodedURL );
+    }
+
+    public void testEncodeURLWithSlashes6()
+        throws URISyntaxException, MalformedURLException
+    {
+        String encodedURL = EncodingUtil.encodeURLToString( "file://host:1/", new String[0] );
+
+        assertEquals( "file://host:1/", encodedURL );
+    }
+
+    public void testEncodeURLWithSlashes7()
+        throws URISyntaxException, MalformedURLException
+    {
+        String encodedURL = EncodingUtil.encodeURLToString( "file://host:1", new String[0] );
+
+        assertEquals( "file://host:1", encodedURL );
+    }
 }