This commit is contained in:
Looly 2021-06-29 23:08:25 +08:00
parent 8caa7f890e
commit 3685f17b3a
3 changed files with 16 additions and 2 deletions

View File

@ -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
{"<", "&lt;"}, // < - less-than

View File

@ -13,9 +13,15 @@ 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[]{"&apos;", "'"}};
/**
* 构造
*/
public XmlUnescape() {
addChain(new LookupReplacer(BASIC_UNESCAPE));
addChain(new NumericEntityUnescaper());
addChain(new LookupReplacer(OTHER_UNESCAPE));
}
}

View File

@ -40,8 +40,16 @@ public class EscapeUtilTest {
@Test
public void escapeSingleQuotesTest(){
// 单引号不做转义
String str = "'some text with single quotes'";
final String s = EscapeUtil.escapeHtml4(str);
Assert.assertEquals("&apos;some text with single quotes&apos;", s);
Assert.assertEquals("'some text with single quotes'", s);
}
@Test
public void unescapeSingleQuotesTest(){
String str = "&apos;some text with single quotes&apos;";
final String s = EscapeUtil.unescapeHtml4(str);
Assert.assertEquals("'some text with single quotes'", s);
}
}