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/16 20:42:38 UTC
[maven-wagon] 01/01: Do things right
This is an automated email from the ASF dual-hosted git repository.
michaelo pushed a commit to branch uri-encoding
in repository https://gitbox.apache.org/repos/asf/maven-wagon.git
commit 5c16627d7d70bc8a181da53bd7016765a1ae1701
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Wed Oct 16 22:42:06 2019 +0200
Do things right
---
.../apache/maven/wagon/shared/http/EncodingUtil.java | 20 ++++++++++----------
.../maven/wagon/shared/http/EncodingUtilTest.java | 2 +-
2 files changed, 11 insertions(+), 11 deletions(-)
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..fd654e0 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,9 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
+import org.apache.http.client.utils.URLEncodedUtils;
+import org.codehaus.plexus.util.StringUtils;
+
/**
* Encoding utility.
*
@@ -86,20 +89,17 @@ 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("/") && StringUtils.isNotEmpty(path))
+ url.deleteCharAt(url.length() - 1);
+
+ url.append(path);
- return encodeURLToString( url.toString() );
+ 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..af9b5e5 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,7 +46,7 @@ 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 );
}