mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix bu
This commit is contained in:
parent
caab40f8ea
commit
783a02cce4
@ -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)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -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();
|
||||||
|
@ -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(){
|
||||||
// 单引号不做转义
|
// 单引号不做转义
|
||||||
|
Loading…
x
Reference in New Issue
Block a user