Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

Commit cc52ad4

Browse files
committed
Fix incorrect param urlencode bug #26
1 parent 0f9c03b commit cc52ad4

File tree

2 files changed

+9
-22
lines changed

2 files changed

+9
-22
lines changed

src/android/src/main/java/com/RNFetchBlob/RNFetchBlob.java

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -160,18 +160,10 @@ public void fetchBlob(ReadableMap options, String taskId, String method, String
160160
RNFetchBlobConfig config = new RNFetchBlobConfig(options);
161161

162162
try {
163-
Uri uri = Uri.parse(url);
164163
AsyncHttpClient req = new AsyncHttpClient();
165164

166-
// set params
167-
RequestParams params = new RequestParams();
168165
AbstractHttpEntity entity = null;
169166

170-
// set params
171-
for (String paramName : uri.getQueryParameterNames()) {
172-
params.put(paramName, uri.getQueryParameter(paramName));
173-
}
174-
175167
// set headers
176168
ReadableMapKeySetIterator it = headers.keySetIterator();
177169
while (it.hasNextKey()) {
@@ -212,7 +204,7 @@ public void fetchBlob(ReadableMap options, String taskId, String method, String
212204
// send request
213205
switch(method.toLowerCase()) {
214206
case "get" :
215-
req.get(url, params, handler);
207+
req.get(url, handler);
216208
break;
217209
case "post" :
218210
req.post(this.getReactApplicationContext(), url, entity, "octet-stream", handler);
@@ -221,7 +213,7 @@ public void fetchBlob(ReadableMap options, String taskId, String method, String
221213
req.put(this.getReactApplicationContext(), url, entity, "octet-stream",handler);
222214
break;
223215
case "delete" :
224-
req.delete(url, params, handler);
216+
req.delete(url, handler);
225217
break;
226218
}
227219
} catch(Exception error) {
@@ -235,16 +227,10 @@ public void fetchBlobForm(ReadableMap options, String taskId, String method, Str
235227

236228
RNFetchBlobConfig config = new RNFetchBlobConfig(options);
237229
try {
238-
Uri uri = Uri.parse(url);
230+
239231
AsyncHttpClient req = new AsyncHttpClient();
240232

241-
// set params
242-
RequestParams params = new RequestParams();
243233
HttpEntity entity = null;
244-
// set params
245-
for (String paramName : uri.getQueryParameterNames()) {
246-
params.put(paramName, uri.getQueryParameter(paramName));
247-
}
248234

249235
// set headers
250236
if(headers != null) {
@@ -307,7 +293,7 @@ public void fetchBlobForm(ReadableMap options, String taskId, String method, Str
307293
// send request
308294
switch(method.toLowerCase()) {
309295
case "get" :
310-
req.get(url, params, handler);
296+
req.get(url, handler);
311297
break;
312298
case "post" :
313299
req.post(this.getReactApplicationContext(), url, entity, "multipart/form-data; charset=utf8", handler);
@@ -316,7 +302,7 @@ public void fetchBlobForm(ReadableMap options, String taskId, String method, Str
316302
req.put(this.getReactApplicationContext(), url, entity, "multipart/form-data",handler);
317303
break;
318304
case "delete" :
319-
req.delete(url, params, handler);
305+
req.delete(url, handler);
320306
break;
321307
}
322308
} catch(Exception error) {

src/ios/RNFetchBlob/RNFetchBlob.m

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ - (NSDictionary *)constantsToExport
6161
form:(NSArray *)form
6262
callback:(RCTResponseSenderBlock)callback)
6363
{
64-
64+
NSString * encodedUrl = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
6565
// send request
6666
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]
6767
initWithURL:[NSURL
68-
URLWithString: url]];
68+
URLWithString: encodedUrl]];
6969

7070
NSMutableDictionary *mheaders = [[NSMutableDictionary alloc] initWithDictionary:[ RNFetchBlobNetwork normalizeHeaders:headers]];
7171

@@ -141,10 +141,11 @@ - (NSDictionary *)constantsToExport
141141
headers:(NSDictionary *)headers
142142
body:(NSString *)body callback:(RCTResponseSenderBlock)callback)
143143
{
144+
NSString * encodedUrl = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
144145
// send request
145146
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]
146147
initWithURL:[NSURL
147-
URLWithString: url]];
148+
URLWithString: encodedUrl]];
148149

149150
NSMutableDictionary *mheaders = [[NSMutableDictionary alloc] initWithDictionary:[RNFetchBlobNetwork normalizeHeaders:headers]];
150151
// move heavy task to another thread

0 commit comments

Comments
 (0)