mirror of
https://github.com/square/okhttp.git
synced 2026-01-17 08:42:25 +03:00
only encode URI problem chars when actually converting to URI
This commit is contained in:
@@ -914,6 +914,12 @@ public final class HttpUrlTest {
|
||||
assertEquals("http://username:password@host/path?query#fragment", uri.toString());
|
||||
}
|
||||
|
||||
@Test public void toUriSpecialQueryCharacters() throws Exception {
|
||||
HttpUrl httpUrl = HttpUrl.parse("http://host/?d=abc!@[]^`{}|\\");
|
||||
URI uri = httpUrl.uri();
|
||||
assertEquals("http://host/?d=abc!@[]%5E%60%7B%7D%7C%5C", uri.toString());
|
||||
}
|
||||
|
||||
@Test public void toUriForbiddenCharacter() throws Exception {
|
||||
HttpUrl httpUrl = HttpUrl.parse("http://host/a[b");
|
||||
try {
|
||||
|
||||
@@ -259,7 +259,8 @@ public final class HttpUrl {
|
||||
static final String PASSWORD_ENCODE_SET = " \"':;<=>@[]^`{}|/\\?#";
|
||||
static final String PATH_SEGMENT_ENCODE_SET = " \"<>^`{}|/\\?#";
|
||||
static final String QUERY_ENCODE_SET = " \"'<>#";
|
||||
static final String QUERY_COMPONENT_ENCODE_SET = " \"'<>#&=^`{}|\\";
|
||||
static final String QUERY_COMPONENT_ENCODE_SET = " \"'<>#&=";
|
||||
static final String CONVERT_TO_URI_ENCODE_SET = "^`{}|\\";
|
||||
static final String FORM_ENCODE_SET = " \"':;<=>@[]^`{}|/\\?#&!$(),~";
|
||||
static final String FRAGMENT_ENCODE_SET = "";
|
||||
|
||||
@@ -331,7 +332,8 @@ public final class HttpUrl {
|
||||
*/
|
||||
public URI uri() {
|
||||
try {
|
||||
return new URI(url);
|
||||
String uriSafeUrl = canonicalize(url, CONVERT_TO_URI_ENCODE_SET, true, false);
|
||||
return new URI(uriSafeUrl);
|
||||
} catch (URISyntaxException e) {
|
||||
throw new IllegalStateException("not valid as a java.net.URI: " + url);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user