Skip to content

Commit

Permalink
[WAGON-602] [Regression] Preserve trailing slash in encoded URL
Browse files Browse the repository at this point in the history
This closes #74
  • Loading branch information
Anatolii Volkodav authored and michael-o committed Nov 24, 2020
1 parent 9b4f2fe commit 370c89f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,13 @@ public static String encodeURLToString( String baseUrl, String path )
{
String[] pathSegments = path == null ? new String[0] : path.split( "/" );

return encodeURLToString( baseUrl, pathSegments );
String encodedUrl = encodeURLToString( baseUrl, pathSegments );
if ( path != null && path.endsWith( "/" ) )
{
return encodedUrl + "/";
}

return encodedUrl;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
public class EncodingUtilTest
extends TestCase
{
public void testEncodeURLWithTrailingSlash()
{
String encodedURL = EncodingUtil.encodeURLToString( "https://host:1234/test", "demo/" );

assertEquals( "https://host:1234/test/demo/", encodedURL );
}

public void testEncodeURLWithSpaces()
throws URISyntaxException, MalformedURLException
{
Expand Down Expand Up @@ -115,4 +122,12 @@ public void testEncodeURLWithSlashes7()

assertEquals( "file://host:1", encodedURL );
}

public void testEncodeURLWithNonLatin()
throws URISyntaxException, MalformedURLException
{
String encodedURL = EncodingUtil.encodeURLToString( "file://host:1", "пипец/" );

assertEquals( "file://host:1/%D0%BF%D0%B8%D0%BF%D0%B5%D1%86/", encodedURL );
}
}

0 comments on commit 370c89f

Please sign in to comment.