mirror of
https://github.com/square/okhttp.git
synced 2026-01-17 08:42:25 +03:00
Handle null fragments.
This commit is contained in:
@@ -1168,4 +1168,24 @@ public final class HttpUrlTest {
|
||||
assertEquals(urlString, url.newBuilder().build().toString());
|
||||
assertEquals("http://%6d%6D:%6d%6D@host/%6d%6D?%6d%6D", url.resolve("").toString());
|
||||
}
|
||||
|
||||
@Test public void clearFragment() throws Exception {
|
||||
HttpUrl url = HttpUrl.parse("http://host/#fragment")
|
||||
.newBuilder()
|
||||
.fragment(null)
|
||||
.build();
|
||||
assertEquals("http://host/", url.toString());
|
||||
assertEquals(null, url.fragment());
|
||||
assertEquals(null, url.encodedFragment());
|
||||
}
|
||||
|
||||
@Test public void clearEncodedFragment() throws Exception {
|
||||
HttpUrl url = HttpUrl.parse("http://host/#fragment")
|
||||
.newBuilder()
|
||||
.encodedFragment(null)
|
||||
.build();
|
||||
assertEquals("http://host/", url.toString());
|
||||
assertEquals(null, url.fragment());
|
||||
assertEquals(null, url.encodedFragment());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -851,14 +851,16 @@ public final class HttpUrl {
|
||||
}
|
||||
|
||||
public Builder fragment(String fragment) {
|
||||
if (fragment == null) throw new IllegalArgumentException("fragment == null");
|
||||
this.encodedFragment = canonicalize(fragment, FRAGMENT_ENCODE_SET, false, false);
|
||||
this.encodedFragment = fragment != null
|
||||
? canonicalize(fragment, FRAGMENT_ENCODE_SET, false, false)
|
||||
: null;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder encodedFragment(String encodedFragment) {
|
||||
if (encodedFragment == null) throw new IllegalArgumentException("encodedFragment == null");
|
||||
this.encodedFragment = canonicalize(encodedFragment, FRAGMENT_ENCODE_SET, true, false);
|
||||
this.encodedFragment = encodedFragment != null
|
||||
? canonicalize(encodedFragment, FRAGMENT_ENCODE_SET, true, false)
|
||||
: null;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user