mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-08-18 20:38:02 +08:00
fix bu
This commit is contained in:
@@ -118,20 +118,24 @@ public class EscapeUtil {
|
||||
}
|
||||
|
||||
final StringBuilder tmp = new StringBuilder(content.length() * 6);
|
||||
char j;
|
||||
char c;
|
||||
for (int i = 0; i < content.length(); i++) {
|
||||
j = content.charAt(i);
|
||||
if (false == filter.accept(j)) {
|
||||
tmp.append(j);
|
||||
} else if (j < 256) {
|
||||
c = content.charAt(i);
|
||||
if (false == filter.accept(c)) {
|
||||
tmp.append(c);
|
||||
} else if (c < 256) {
|
||||
tmp.append("%");
|
||||
if (j < 16) {
|
||||
if (c < 16) {
|
||||
tmp.append("0");
|
||||
}
|
||||
tmp.append(Integer.toString(j, 16));
|
||||
tmp.append(Integer.toString(c, 16));
|
||||
} else {
|
||||
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();
|
||||
|
@@ -38,6 +38,20 @@ public class EscapeUtilTest {
|
||||
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
|
||||
public void escapeSingleQuotesTest(){
|
||||
// 单引号不做转义
|
||||
|
Reference in New Issue
Block a user