mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
修复XmlUtil转义调用方法错误问题,修复XmlEscape未转义单引号问题(pr#3837@Github)
This commit is contained in:
parent
50df86d846
commit
5befdeea3f
@ -2,12 +2,13 @@
|
|||||||
# 🚀Changelog
|
# 🚀Changelog
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
# 5.8.36(2025-01-02)
|
# 5.8.36(2025-01-09)
|
||||||
|
|
||||||
### 🐣新特性
|
### 🐣新特性
|
||||||
* 【crypto 】 增加BCUtil.decodeECPrivateKey方法(issue#3829@Github)
|
* 【crypto 】 增加BCUtil.decodeECPrivateKey方法(issue#3829@Github)
|
||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
* 【aop 】 修复ProxyUtil可能的空指针问题(issue#IBF20Z@Gitee)
|
* 【aop 】 修复ProxyUtil可能的空指针问题(issue#IBF20Z@Gitee)
|
||||||
|
* 【core 】 修复XmlUtil转义调用方法错误问题,修复XmlEscape未转义单引号问题(pr#3837@Github)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
# 5.8.35(2024-12-25)
|
# 5.8.35(2024-12-25)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package cn.hutool.core.text.escape;
|
package cn.hutool.core.text.escape;
|
||||||
|
|
||||||
import cn.hutool.core.text.replacer.LookupReplacer;
|
import cn.hutool.core.text.replacer.LookupReplacer;
|
||||||
|
import cn.hutool.core.text.replacer.ReplacerChain;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HTML4的ESCAPE
|
* HTML4的ESCAPE
|
||||||
@ -9,9 +10,21 @@ import cn.hutool.core.text.replacer.LookupReplacer;
|
|||||||
* @author looly
|
* @author looly
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class Html4Escape extends XmlEscape {
|
public class Html4Escape extends ReplacerChain {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HTML转义字符<br>
|
||||||
|
* HTML转义相比XML,并不转义单引号<br>
|
||||||
|
* 见: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 = { //
|
protected static final String[][] ISO8859_1_ESCAPE = { //
|
||||||
{ "\u00A0", " " }, // non-breaking space
|
{ "\u00A0", " " }, // non-breaking space
|
||||||
{ "\u00A1", "¡" }, // inverted exclamation mark
|
{ "\u00A1", "¡" }, // inverted exclamation mark
|
||||||
@ -310,6 +323,7 @@ public class Html4Escape extends XmlEscape {
|
|||||||
|
|
||||||
public Html4Escape() {
|
public Html4Escape() {
|
||||||
super();
|
super();
|
||||||
|
addChain(new LookupReplacer(BASIC_ESCAPE));
|
||||||
addChain(new LookupReplacer(ISO8859_1_ESCAPE));
|
addChain(new LookupReplacer(ISO8859_1_ESCAPE));
|
||||||
addChain(new LookupReplacer(HTML40_EXTENDED_ESCAPE));
|
addChain(new LookupReplacer(HTML40_EXTENDED_ESCAPE));
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import cn.hutool.core.lang.Console;
|
|||||||
import cn.hutool.core.map.MapBuilder;
|
import cn.hutool.core.map.MapBuilder;
|
||||||
import cn.hutool.core.map.MapUtil;
|
import cn.hutool.core.map.MapUtil;
|
||||||
import lombok.Data;
|
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.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
@ -22,6 +22,8 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link XmlUtil} 工具类
|
* {@link XmlUtil} 工具类
|
||||||
*
|
*
|
||||||
@ -319,8 +321,8 @@ public class XmlUtilTest {
|
|||||||
public void escapeTest(){
|
public void escapeTest(){
|
||||||
final String a = "<>";
|
final String a = "<>";
|
||||||
final String escape = XmlUtil.escape(a);
|
final String escape = XmlUtil.escape(a);
|
||||||
Console.log(escape);
|
Assertions.assertEquals("<>", escape);
|
||||||
Console.log(XmlUtil.escape("中文“双引号”"));
|
Assertions.assertEquals("中文“双引号”", XmlUtil.escape("中文“双引号”"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user