修复PunyCode处理域名的问题

This commit is contained in:
Looly 2022-09-20 22:54:58 +08:00
parent 1d3cf0d1a7
commit 5f68c73938
3 changed files with 23 additions and 1 deletions

View File

@ -13,6 +13,7 @@
### 🐞Bug修复
* 【core 】 修复FileNameUtil.cleanInvalid无法去除换行符问题issue#I5RMZV@Gitee
* 【core 】 修复murmur3_32实现错误pr#2616@Github
* 【core 】 修复PunyCode处理域名的问题pr#2620@Github
-------------------------------------------------------------------------------------------------------------

View File

@ -85,6 +85,10 @@ public class PunyCode {
}
// Append delimiter
if (b > 0) {
if(b == length){
// 无需要编码的字符
return output.toString();
}
output.append(DELIMITER);
}
int h = b;
@ -158,7 +162,7 @@ public class PunyCode {
if (result.length() != 0) {
result.append(CharUtil.DOT);
}
result.append(decode(str));
result.append(StrUtil.startWithIgnoreEquals(str, PUNY_CODE_PREFIX) ? decode(str) : str);
}
return result.toString();

View File

@ -16,6 +16,14 @@ public class PunyCodeTest {
Assert.assertEquals(text, decode);
}
@Test
public void encodeDecodeTest2(){
// 无需编码和解码
String text = "Hutool";
String strPunyCode = PunyCode.encode(text);
Assert.assertEquals("Hutool", strPunyCode);
}
@Test
public void encodeEncodeDomainTest(){
String domain = "赵新虎.中国";
@ -23,4 +31,13 @@ public class PunyCodeTest {
String decode = PunyCode.decodeDomain(strPunyCode);
Assert.assertEquals(decode, domain);
}
@Test
public void encodeEncodeDomainTest2(){
String domain = "赵新虎.com";
String strPunyCode = PunyCode.encodeDomain(domain);
Assert.assertEquals("xn--efvz93e52e.com", strPunyCode);
String decode = PunyCode.decodeDomain(strPunyCode);
Assert.assertEquals(domain, decode);
}
}