fix: 修复 XmlUtil 中转义/反转义方法错误调用 html4 转义/反转义方法的问题。html4 转义会将中文双引号等字符转义为 xml 无法识别的字符,从而导致解析 xml 时出现异常

This commit is contained in:
Zhenheng.Xie 2025-01-09 17:09:23 +08:00
parent 8c81e43a07
commit 307670b50d
2 changed files with 4 additions and 2 deletions

View File

@ -956,6 +956,7 @@ public class XmlUtil {
* < (小于) 替换为 <
* > (大于) 替换为 >
* " (双引号) 替换为 "
* ' (单引号) 替换为 '
* </pre>
*
* @param string 被替换的字符串
@ -963,7 +964,7 @@ public class XmlUtil {
* @since 4.0.8
*/
public static String escape(String string) {
return EscapeUtil.escapeHtml4(string);
return EscapeUtil.escapeXml(string);
}
/**
@ -975,7 +976,7 @@ public class XmlUtil {
* @since 5.0.6
*/
public static String unescape(String string) {
return EscapeUtil.unescapeHtml4(string);
return EscapeUtil.unescapeXml(string);
}
/**

View File

@ -320,6 +320,7 @@ public class XmlUtilTest {
final String a = "<>";
final String escape = XmlUtil.escape(a);
Console.log(escape);
Console.log(XmlUtil.escape("中文“双引号”"));
}
@Test