Skip to content
This repository has been archived by the owner on Sep 26, 2022. It is now read-only.

Commit

Permalink
fix(android): Ensure proper URL formatting without encoding, skip set…
Browse files Browse the repository at this point in the history
…Params if empty (#178)
  • Loading branch information
jesperbjerke authored Nov 10, 2021
1 parent f3ac495 commit 4065a02
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ public HttpURLConnectionBuilder setUrlParams(JSObject params, boolean shouldEnco
String initialQueryBuilderStr = initialQuery == null ? "" : initialQuery;

Iterator<String> keys = params.keys();

if (!keys.hasNext()) {
return this;
}

StringBuilder urlQueryBuilder = new StringBuilder(initialQueryBuilderStr);

// Build the new query string
Expand Down Expand Up @@ -162,7 +167,7 @@ public HttpURLConnectionBuilder setUrlParams(JSObject params, boolean shouldEnco
URI encodedUri = new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), urlQuery, uri.getFragment());
this.url = encodedUri.toURL();
} else {
String unEncodedUrlString = uri.getScheme() + uri.getAuthority() + uri.getPath() + urlQuery + uri.getFragment();
String unEncodedUrlString = uri.getScheme() + "://" + uri.getAuthority() + uri.getPath() + ((!urlQuery.equals("")) ? "?" + urlQuery : "") + ((uri.getFragment() != null) ? uri.getFragment() : "");
this.url = new URL(unEncodedUrlString);
}

Expand Down Expand Up @@ -362,6 +367,7 @@ public static JSObject request(PluginCall call, String httpMethod) throws IOExce
Integer connectTimeout = call.getInt("connectTimeout");
Integer readTimeout = call.getInt("readTimeout");
Boolean disableRedirects = call.getBoolean("disableRedirects");
Boolean shouldEncode = call.getBoolean("shouldEncodeUrlParams", true);
ResponseType responseType = ResponseType.parse(call.getString("responseType"));

String method = httpMethod != null ? httpMethod.toUpperCase() : call.getString("method", "").toUpperCase();
Expand All @@ -373,7 +379,7 @@ public static JSObject request(PluginCall call, String httpMethod) throws IOExce
.setUrl(url)
.setMethod(method)
.setHeaders(headers)
.setUrlParams(params)
.setUrlParams(params, shouldEncode)
.setConnectTimeout(connectTimeout)
.setReadTimeout(readTimeout)
.setDisableRedirects(disableRedirects)
Expand Down

0 comments on commit 4065a02

Please sign in to comment.