From 307670b50d200df6432c889679be02152964f7b9 Mon Sep 17 00:00:00 2001 From: "Zhenheng.Xie" Date: Thu, 9 Jan 2025 17:09:23 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20XmlUtil=20?= =?UTF-8?q?=E4=B8=AD=E8=BD=AC=E4=B9=89/=E5=8F=8D=E8=BD=AC=E4=B9=89?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E9=94=99=E8=AF=AF=E8=B0=83=E7=94=A8=20html4?= =?UTF-8?q?=20=E8=BD=AC=E4=B9=89/=E5=8F=8D=E8=BD=AC=E4=B9=89=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82html4=20=E8=BD=AC?= =?UTF-8?q?=E4=B9=89=E4=BC=9A=E5=B0=86=E4=B8=AD=E6=96=87=E5=8F=8C=E5=BC=95?= =?UTF-8?q?=E5=8F=B7=E7=AD=89=E5=AD=97=E7=AC=A6=E8=BD=AC=E4=B9=89=E4=B8=BA?= =?UTF-8?q?=20xml=20=E6=97=A0=E6=B3=95=E8=AF=86=E5=88=AB=E7=9A=84=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=EF=BC=8C=E4=BB=8E=E8=80=8C=E5=AF=BC=E8=87=B4=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=20xml=20=E6=97=B6=E5=87=BA=E7=8E=B0=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hutool-core/src/main/java/cn/hutool/core/util/XmlUtil.java | 5 +++-- .../src/test/java/cn/hutool/core/util/XmlUtilTest.java | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/hutool-core/src/main/java/cn/hutool/core/util/XmlUtil.java b/hutool-core/src/main/java/cn/hutool/core/util/XmlUtil.java index 1b42ff9a3..1d77b0012 100755 --- a/hutool-core/src/main/java/cn/hutool/core/util/XmlUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/util/XmlUtil.java @@ -956,6 +956,7 @@ public class XmlUtil { * < (小于) 替换为 &lt; * > (大于) 替换为 &gt; * " (双引号) 替换为 &quot; + * ' (单引号) 替换为 &apos; * * * @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); } /** 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 6f0932082..cb7a2d9f5 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 @@ -320,6 +320,7 @@ public class XmlUtilTest { final String a = "<>"; final String escape = XmlUtil.escape(a); Console.log(escape); + Console.log(XmlUtil.escape("中文“双引号”")); } @Test From f4cf4dc21fac347393f8997d867767f5f475b353 Mon Sep 17 00:00:00 2001 From: "Zhenheng.Xie" Date: Thu, 9 Jan 2025 17:12:51 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20XmlEscape=20?= =?UTF-8?q?=E6=9C=AA=E5=AF=B9=E5=8D=95=E5=BC=95=E5=8F=B7=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E8=BD=AC=E4=B9=89=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/cn/hutool/core/text/escape/XmlEscape.java | 2 +- .../src/main/java/cn/hutool/core/text/escape/XmlUnescape.java | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/hutool-core/src/main/java/cn/hutool/core/text/escape/XmlEscape.java b/hutool-core/src/main/java/cn/hutool/core/text/escape/XmlEscape.java index 8aba9e2a7..461b1c90a 100644 --- a/hutool-core/src/main/java/cn/hutool/core/text/escape/XmlEscape.java +++ b/hutool-core/src/main/java/cn/hutool/core/text/escape/XmlEscape.java @@ -22,7 +22,7 @@ public class XmlEscape extends ReplacerChain { private static final long serialVersionUID = 1L; protected static final String[][] BASIC_ESCAPE = { // -// {"'", "'"}, // " - single-quote + {"'", "'"}, // " - single-quote {"\"", """}, // " - double-quote {"&", "&"}, // & - ampersand {"<", "<"}, // < - less-than diff --git a/hutool-core/src/main/java/cn/hutool/core/text/escape/XmlUnescape.java b/hutool-core/src/main/java/cn/hutool/core/text/escape/XmlUnescape.java index 80073a9c1..dee798851 100644 --- a/hutool-core/src/main/java/cn/hutool/core/text/escape/XmlUnescape.java +++ b/hutool-core/src/main/java/cn/hutool/core/text/escape/XmlUnescape.java @@ -13,8 +13,6 @@ public class XmlUnescape extends ReplacerChain { private static final long serialVersionUID = 1L; protected static final String[][] BASIC_UNESCAPE = InternalEscapeUtil.invert(XmlEscape.BASIC_ESCAPE); - // issue#1118 - protected static final String[][] OTHER_UNESCAPE = new String[][]{new String[]{"'", "'"}}; /** * 构造 @@ -22,6 +20,5 @@ public class XmlUnescape extends ReplacerChain { public XmlUnescape() { addChain(new LookupReplacer(BASIC_UNESCAPE)); addChain(new NumericEntityUnescaper()); - addChain(new LookupReplacer(OTHER_UNESCAPE)); } }