mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
修复PunyCode处理域名的问题
This commit is contained in:
parent
1d3cf0d1a7
commit
5f68c73938
@ -13,6 +13,7 @@
|
|||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
* 【core 】 修复FileNameUtil.cleanInvalid无法去除换行符问题(issue#I5RMZV@Gitee)
|
* 【core 】 修复FileNameUtil.cleanInvalid无法去除换行符问题(issue#I5RMZV@Gitee)
|
||||||
* 【core 】 修复murmur3_32实现错误(pr#2616@Github)
|
* 【core 】 修复murmur3_32实现错误(pr#2616@Github)
|
||||||
|
* 【core 】 修复PunyCode处理域名的问题(pr#2620@Github)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -85,6 +85,10 @@ public class PunyCode {
|
|||||||
}
|
}
|
||||||
// Append delimiter
|
// Append delimiter
|
||||||
if (b > 0) {
|
if (b > 0) {
|
||||||
|
if(b == length){
|
||||||
|
// 无需要编码的字符
|
||||||
|
return output.toString();
|
||||||
|
}
|
||||||
output.append(DELIMITER);
|
output.append(DELIMITER);
|
||||||
}
|
}
|
||||||
int h = b;
|
int h = b;
|
||||||
@ -158,7 +162,7 @@ public class PunyCode {
|
|||||||
if (result.length() != 0) {
|
if (result.length() != 0) {
|
||||||
result.append(CharUtil.DOT);
|
result.append(CharUtil.DOT);
|
||||||
}
|
}
|
||||||
result.append(decode(str));
|
result.append(StrUtil.startWithIgnoreEquals(str, PUNY_CODE_PREFIX) ? decode(str) : str);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result.toString();
|
return result.toString();
|
||||||
|
@ -16,6 +16,14 @@ public class PunyCodeTest {
|
|||||||
Assert.assertEquals(text, decode);
|
Assert.assertEquals(text, decode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void encodeDecodeTest2(){
|
||||||
|
// 无需编码和解码
|
||||||
|
String text = "Hutool";
|
||||||
|
String strPunyCode = PunyCode.encode(text);
|
||||||
|
Assert.assertEquals("Hutool", strPunyCode);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void encodeEncodeDomainTest(){
|
public void encodeEncodeDomainTest(){
|
||||||
String domain = "赵新虎.中国";
|
String domain = "赵新虎.中国";
|
||||||
@ -23,4 +31,13 @@ public class PunyCodeTest {
|
|||||||
String decode = PunyCode.decodeDomain(strPunyCode);
|
String decode = PunyCode.decodeDomain(strPunyCode);
|
||||||
Assert.assertEquals(decode, domain);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user