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 16:19:15 UTC

[maven-wagon] branch WAGON-569 updated (d06720e -> 3e34ecc)

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 d06720e  [WAGON-569] Inconsistent encoding behavior for repository URLs with spaces
     add e6c8e91  WAGON-541 add consistency to exception messages for all wagons so that clients ( ie. Maven ) reporting the Exceptions to users have good consistent contextual information. This means also report any custom status line reason phrases the servers involved might return.
     add 7bfe244  WAGON-541 fixed code style in tests
     add d77d88b  WAGON-541 code dedupe
     add 003c1f6  WAGON-541 code simplification
     add 372aa52  WAGON-541 added a note on Reason Phrase future
     new 3e34ecc  [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   (d06720e)
            \
             N -- N -- N   refs/heads/WAGON-569 (3e34ecc)

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/http/HttpWagonTestCase.java | 133 ++++++++++--
 .../wagon/providers/http/LightweightHttpWagon.java | 181 ++++++++++++----
 .../providers/http/LightweightHttpWagonTest.java   | 107 ++++++++++
 .../wagon/shared/http/AbstractHttpClientWagon.java | 122 ++++-------
 .../maven/wagon/shared/http/HttpMessageUtils.java  | 230 +++++++++++++++++++++
 .../maven/wagon/providers/http/HttpWagon.java      |  22 +-
 .../providers/http/ErrorWithMessageServlet.java    |   4 +
 .../wagon/providers/http/HttpWagonErrorTest.java   |  69 ++++++-
 .../wagon/providers/webdav/WebDavWagonTest.java    |   7 +
 .../apache/maven/wagon/tck/http/Assertions.java    | 137 +++++++++++-
 .../apache/maven/wagon/tck/http/GetWagonTests.java |  35 +---
 11 files changed, 867 insertions(+), 180 deletions(-)
 create mode 100644 wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/HttpMessageUtils.java


[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 3e34eccf5a8e33c95a16d919a7c11bf62f21bceb
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      | 27 ++++++----
 .../maven/wagon/shared/http/EncodingUtilTest.java  | 59 +++++++++++++++++++++-
 3 files changed, 87 insertions(+), 17 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..1d74280 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
@@ -77,8 +83,8 @@ public class EncodingUtil
     /**
      * Parses and returns an encoded version of the given URL string alongside the given paths.
      *
-     * @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.
+     * @param baseUrl Base URL to use when constructing the final URL. This has to be a valid URL already.
+     * @param paths   Additional unencoded path(s) to append at the end of the base path.
      * @return Composed URL (base + paths) already encoded, separating the individual path components by "/".
      * @since TODO
      */
@@ -86,20 +92,19 @@ public class EncodingUtil
     {
         StringBuilder url = new StringBuilder( baseUrl );
 
-        String[] parts = paths == null ? //
+        String[] segments = paths == null ? //
             new String[0] : //
             paths.length == 1 ? paths[0].split( "/" ) : paths;
 
-        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..e7fab98 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,65 @@ 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", new String[] {"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/", new String[] {"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",
+                                                            new String[] {"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 );
+    }
 }