This commit is contained in:
Looly 2021-09-10 19:51:46 +08:00
parent caab40f8ea
commit 783a02cce4
3 changed files with 27 additions and 8 deletions

View File

@ -10,6 +10,7 @@
* 【core 】 修复FuncKey函数无效问题 * 【core 】 修复FuncKey函数无效问题
* 【core 】 修复ImgUtil.copyImage读取网络URL后宽高报错问题issue#1821@Github * 【core 】 修复ImgUtil.copyImage读取网络URL后宽高报错问题issue#1821@Github
* 【core 】 修复StrJoiner.append配置丢失问题issue#I49K1L@Gitee * 【core 】 修复StrJoiner.append配置丢失问题issue#I49K1L@Gitee
* 【core 】 修复EscapeUtil特殊字符的hex长度不足导致的问题issue#I49JU8@Gitee
------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------

View File

@ -118,20 +118,24 @@ public class EscapeUtil {
} }
final StringBuilder tmp = new StringBuilder(content.length() * 6); final StringBuilder tmp = new StringBuilder(content.length() * 6);
char j; char c;
for (int i = 0; i < content.length(); i++) { for (int i = 0; i < content.length(); i++) {
j = content.charAt(i); c = content.charAt(i);
if (false == filter.accept(j)) { if (false == filter.accept(c)) {
tmp.append(j); tmp.append(c);
} else if (j < 256) { } else if (c < 256) {
tmp.append("%"); tmp.append("%");
if (j < 16) { if (c < 16) {
tmp.append("0"); tmp.append("0");
} }
tmp.append(Integer.toString(j, 16)); tmp.append(Integer.toString(c, 16));
} else { } else {
tmp.append("%u"); tmp.append("%u");
tmp.append(Integer.toString(j, 16)); if(c <= 0xfff){
// issue#I49JU8@Gitee
tmp.append("0");
}
tmp.append(Integer.toString(c, 16));
} }
} }
return tmp.toString(); return tmp.toString();

View File

@ -38,6 +38,20 @@ public class EscapeUtilTest {
Assert.assertEquals(str, unescape); Assert.assertEquals(str, unescape);
} }
/**
* https://gitee.com/dromara/hutool/issues/I49JU8
*/
@Test
public void escapeAllTest2(){
String str = "٩";
String escape = EscapeUtil.escapeAll(str);
Assert.assertEquals("%u0669", escape);
String unescape = EscapeUtil.unescape(escape);
Assert.assertEquals(str, unescape);
}
@Test @Test
public void escapeSingleQuotesTest(){ public void escapeSingleQuotesTest(){
// 单引号不做转义 // 单引号不做转义