mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
UrlBuilder的toURI方法将url重复编码
This commit is contained in:
@@ -544,12 +544,7 @@ public final class UrlBuilder implements Builder<String> {
|
||||
*/
|
||||
public URI toURI() {
|
||||
try {
|
||||
return new URI(
|
||||
getSchemeWithDefault(),
|
||||
getAuthority(),
|
||||
getPathStr(),
|
||||
getQueryStr(),
|
||||
getFragmentEncoded());
|
||||
return toURL().toURI();
|
||||
} catch (URISyntaxException e) {
|
||||
return null;
|
||||
}
|
||||
|
@@ -445,4 +445,21 @@ public class UrlBuilderTest {
|
||||
final UrlBuilder of = UrlBuilder.of(url, null);
|
||||
Assert.assertEquals(url.replace("&", "&"), of.toString());
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@Test
|
||||
public void issues2503Test() throws URISyntaxException {
|
||||
String duplicate = UrlBuilder.ofHttp("127.0.0.1:8080")
|
||||
.addQuery("param[0].field", "编码")
|
||||
.toURI()
|
||||
.toString();
|
||||
Assert.assertEquals("http://127.0.0.1:8080?param%5B0%5D.field=%E7%BC%96%E7%A0%81", duplicate);
|
||||
|
||||
String normal = UrlBuilder.ofHttp("127.0.0.1:8080")
|
||||
.addQuery("param[0].field", "编码")
|
||||
.toURL()
|
||||
.toURI()
|
||||
.toString();
|
||||
Assert.assertEquals(duplicate, normal);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user