UrlBuilder的toURI方法将url重复编码

This commit is contained in:
Looly 2022-08-09 21:14:49 +08:00
parent c4a33819b3
commit 0fdec254ed
4 changed files with 25 additions and 6 deletions

View File

@ -10,6 +10,7 @@
* 【http 】 修复https下可能的Patch、Get请求失效问题issue#I3Z3DH@Gitee
* 【core 】 修复RandomUtil#randomString 入参length为负数时报错问题issue#2515@Github
* 【core 】 修复SecureUtil传入null的key抛出异常问题pr#2521@Github
* 【core 】 修复UrlBuilder的toURI方法将url重复编码issue#2503@Github
-------------------------------------------------------------------------------------------------------------

View File

@ -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;
}

View File

@ -445,4 +445,21 @@ public class UrlBuilderTest {
final UrlBuilder of = UrlBuilder.of(url, null);
Assert.assertEquals(url.replace("&amp;", "&"), 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);
}
}

View File

@ -132,4 +132,10 @@ public class DbTest {
return ps;
}), new EntityListHandler());
}
@Test
@Ignore
public void findWithDotTest() throws SQLException {
Db.use().find(Entity.create("user").set("a.b", "1"));
}
}