-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(android): incorrect http url params encoding (#6586)
Co-authored-by: jcesarmobile <[email protected]>
- Loading branch information
1 parent
00b7abf
commit e5e692c
Showing
2 changed files
with
62 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
android/capacitor/src/test/java/com/getcapacitor/plugin/util/HttpRequestHandlerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.getcapacitor.plugin.util; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import com.getcapacitor.JSObject; | ||
import com.getcapacitor.plugin.util.HttpRequestHandler.HttpURLConnectionBuilder; | ||
import java.net.URL; | ||
import org.junit.Test; | ||
|
||
public class HttpRequestHandlerTest { | ||
|
||
static final String BASE_URL = "https://httpbin.org/get"; | ||
static final String PARAMS_JSON = """ | ||
{"k": "a&b"} | ||
"""; | ||
|
||
@Test | ||
public void testHttpURLConnectionBuilderSetUrlParamsEncoded() throws Exception { | ||
String expectedQuery = "k=a%26b"; | ||
String expectedUrl = BASE_URL + "?" + expectedQuery; | ||
String actualUrl = new HttpURLConnectionBuilder() | ||
.setUrl(new URL(BASE_URL)) | ||
.setUrlParams(new JSObject(PARAMS_JSON), true) | ||
.url.toString(); | ||
assertEquals(expectedUrl, actualUrl); | ||
} | ||
|
||
@Test | ||
public void testHttpURLConnectionBuilderSetUrlParamsNotEncoded() throws Exception { | ||
String expectedQuery = "k=a&b"; | ||
String expectedUrl = BASE_URL + "?" + expectedQuery; | ||
String actualUrl = new HttpURLConnectionBuilder() | ||
.setUrl(new URL(BASE_URL)) | ||
.setUrlParams(new JSObject(PARAMS_JSON), false) | ||
.url.toString(); | ||
assertEquals(expectedUrl, actualUrl); | ||
} | ||
} |