diff --git a/CHANGELOG.md b/CHANGELOG.md
index 36d0cb044..61b3553bd 100755
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,12 +2,13 @@
# 🚀Changelog
-------------------------------------------------------------------------------------------------------------
-# 5.8.36(2025-01-02)
+# 5.8.36(2025-01-09)
### 🐣新特性
* 【crypto 】 增加BCUtil.decodeECPrivateKey方法(issue#3829@Github)
### 🐞Bug修复
* 【aop 】 修复ProxyUtil可能的空指针问题(issue#IBF20Z@Gitee)
+* 【core 】 修复XmlUtil转义调用方法错误问题,修复XmlEscape未转义单引号问题(pr#3837@Github)
-------------------------------------------------------------------------------------------------------------
# 5.8.35(2024-12-25)
diff --git a/hutool-core/src/main/java/cn/hutool/core/text/escape/Html4Escape.java b/hutool-core/src/main/java/cn/hutool/core/text/escape/Html4Escape.java
index 023ab98bc..8473e417d 100644
--- a/hutool-core/src/main/java/cn/hutool/core/text/escape/Html4Escape.java
+++ b/hutool-core/src/main/java/cn/hutool/core/text/escape/Html4Escape.java
@@ -1,6 +1,7 @@
package cn.hutool.core.text.escape;
import cn.hutool.core.text.replacer.LookupReplacer;
+import cn.hutool.core.text.replacer.ReplacerChain;
/**
* HTML4的ESCAPE
@@ -9,9 +10,21 @@ import cn.hutool.core.text.replacer.LookupReplacer;
* @author looly
*
*/
-public class Html4Escape extends XmlEscape {
+public class Html4Escape extends ReplacerChain {
private static final long serialVersionUID = 1L;
+ /**
+ * HTML转义字符
+ * HTML转义相比XML,并不转义单引号
+ * 见:https://stackoverflow.com/questions/1091945/what-characters-do-i-need-to-escape-in-xml-documents
+ */
+ protected static final String[][] BASIC_ESCAPE = { //
+ {"\"", """}, // " - double-quote
+ {"&", "&"}, // & - ampersand
+ {"<", "<"}, // < - less-than
+ {">", ">"}, // > - greater-than
+ };
+
protected static final String[][] ISO8859_1_ESCAPE = { //
{ "\u00A0", " " }, // non-breaking space
{ "\u00A1", "¡" }, // inverted exclamation mark
@@ -310,6 +323,7 @@ public class Html4Escape extends XmlEscape {
public Html4Escape() {
super();
+ addChain(new LookupReplacer(BASIC_ESCAPE));
addChain(new LookupReplacer(ISO8859_1_ESCAPE));
addChain(new LookupReplacer(HTML40_EXTENDED_ESCAPE));
}
diff --git a/hutool-core/src/test/java/cn/hutool/core/util/XmlUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/util/XmlUtilTest.java
index cb7a2d9f5..373aa323a 100644
--- a/hutool-core/src/test/java/cn/hutool/core/util/XmlUtilTest.java
+++ b/hutool-core/src/test/java/cn/hutool/core/util/XmlUtilTest.java
@@ -7,7 +7,7 @@ import cn.hutool.core.lang.Console;
import cn.hutool.core.map.MapBuilder;
import cn.hutool.core.map.MapUtil;
import lombok.Data;
-import static org.junit.jupiter.api.Assertions.*;
+import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.w3c.dom.Document;
@@ -22,6 +22,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import static org.junit.jupiter.api.Assertions.*;
+
/**
* {@link XmlUtil} 工具类
*
@@ -319,8 +321,8 @@ public class XmlUtilTest {
public void escapeTest(){
final String a = "<>";
final String escape = XmlUtil.escape(a);
- Console.log(escape);
- Console.log(XmlUtil.escape("中文“双引号”"));
+ Assertions.assertEquals("<>", escape);
+ Assertions.assertEquals("中文“双引号”", XmlUtil.escape("中文“双引号”"));
}
@Test