Skip to content
This repository has been archived by the owner on Dec 25, 2024. It is now read-only.

Commit

Permalink
Make cleanUrl non-static so that APIs can overwrite it (#614)
Browse files Browse the repository at this point in the history
cleanUrl replaces missing values in key-value-pairs with an empty string so that
?param&... becomes ?param=&... . This may lead to problems in some cases (e.g.
at SLUBApi when resolving libero references in getDetailById). Even it we'd
replace the "" by null in the else branch of the current implementation, a
trailing = will still be be added by URLEncodedUtils.format, as Android uses
httpclient-android version 4.3.5.1 which has a bug to add a trailing = sign
to key-only parameters by replacing missing parameters with empty strings the
same way clearUrl does (versions 4.5 and newer work correctly but can't be
used by Android, see also https://hc.apache.org/httpcomponents-client-4.5.x/android.html.

To avoid this we make cleanUrl non-static so that APIs can overwrite
it with their own version as needed.
  • Loading branch information
StefRe authored Mar 26, 2021
1 parent 5e7cdb1 commit b3d545d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ protected JSONObject loadJsonResource(String filename) {
* @param myURL the URL to clean
* @return cleaned URL
*/
public static String cleanUrl(String myURL) {
public String cleanUrl(String myURL) {
String[] parts = myURL.split("\\?");
String url = parts[0];
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.junit.Test;
import org.mockito.Mockito;

import java.util.Arrays;

Expand All @@ -12,10 +13,11 @@

public class ApacheBaseApiTest {
@Test
public void cleanUrlShouldHandleMultipleEqualsSigns() throws Exception {
public void cleanUrlShouldHandleMultipleEqualsSigns() {
BaseApi baseApi = Mockito.mock(BaseApi.class, Mockito.CALLS_REAL_METHODS);
String url = "http://www.example.com/file?param1=value=1&param=value2";
assertEquals("http://www.example.com/file?param1=value%3D1&param=value2",
ApacheBaseApi.cleanUrl(url));
baseApi.cleanUrl(url));
}

@Test
Expand Down

0 comments on commit b3d545d

Please sign in to comment.