Skip to content

Commit

Permalink
Using standardised way of encoding URLs, Closing #691
Browse files Browse the repository at this point in the history
  • Loading branch information
smarek committed Sep 13, 2014
1 parent 75c34f9 commit b3e15c3
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions library/src/main/java/com/loopj/android/http/AsyncHttpClient.java
Expand Up @@ -73,8 +73,10 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PushbackInputStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.net.URI;
import java.net.URLEncoder;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
Expand Down Expand Up @@ -1225,8 +1227,14 @@ public static String getUrlWithQueryString(boolean shouldEncodeUrl, String url,
if (url == null)
return null;

if (shouldEncodeUrl)
url = url.replace(" ", "%20");
if (shouldEncodeUrl) {
try {
url = URLEncoder.encode(url, "UTF-8");
} catch (UnsupportedEncodingException e) {
// Should not really happen, added just for sake of validity
Log.e(LOG_TAG, "getUrlWithQueryString encoding URL", e);
}
}

if (params != null) {
// Construct the query string and trim it, in case it
Expand Down

0 comments on commit b3e15c3

Please sign in to comment.