本文整理了Java中org.apache.commons.lang3.StringEscapeUtils.unescapeHtml4()
方法的一些代码示例,展示了StringEscapeUtils.unescapeHtml4()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringEscapeUtils.unescapeHtml4()
方法的具体详情如下:
包路径:org.apache.commons.lang3.StringEscapeUtils
类名称:StringEscapeUtils
方法名:unescapeHtml4
[英]Unescapes a string containing entity escapes to a string containing the actual Unicode characters corresponding to the escapes. Supports HTML 4.0 entities.
For example, the string "<Français>"will become ""
If an entity is unrecognized, it is left alone, and inserted verbatim into the result string. e.g. ">&zzzz;x" will become ">&zzzz;x".
[中]unescape将包含实体转义的字符串转换为包含与转义相对应的实际Unicode字符的字符串。支持HTML4.0实体。
例如,字符串“<Français>”将变为“
如果一个实体无法识别,它将被单独保留,并逐字插入结果字符串。e、 g.“>&zzzz;x”将变成“>&zzzz;x”。
代码示例来源:origin: springside/springside4
/**
* Html解码,将HTML4格式的字符串转码解码为普通字符串.
*
* 比如 "bread" & "butter"转化为"bread" & "butter"
*/
public static String unescapeHtml(String html) {
return StringEscapeUtils.unescapeHtml4(html);
}
}
代码示例来源:origin: signalapp/BitHub
public String parseDestinationFromMessage() {
String message = StringEscapeUtils.unescapeHtml4(coinbaseTransaction.getNotes());
int startToken = message.indexOf("__");
if (startToken == -1) {
return "Unknown";
}
int endToken = message.indexOf("__", startToken + 1);
if (endToken == -1) {
return "Unknown";
}
return message.substring(startToken+2, endToken);
}
代码示例来源:origin: signalapp/BitHub
public String parseUrlFromMessage() throws ParseException {
String message = StringEscapeUtils.unescapeHtml4(coinbaseTransaction.getNotes());
int urlIndex = message.indexOf("https://");
return message.substring(urlIndex).trim();
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testUnescapeHexCharsHtml() {
// Simple easy to grok test
assertEquals("hex number unescape", "\u0080\u009F", StringEscapeUtils.unescapeHtml4("€Ÿ"));
assertEquals("hex number unescape", "\u0080\u009F", StringEscapeUtils.unescapeHtml4("€Ÿ"));
// Test all Character values:
for (char i = Character.MIN_VALUE; i < Character.MAX_VALUE; i++) {
final Character c1 = new Character(i);
final Character c2 = new Character((char)(i+1));
final String expected = c1.toString() + c2.toString();
final String escapedC1 = "&#x" + Integer.toHexString((c1.charValue())) + ";";
final String escapedC2 = "&#x" + Integer.toHexString((c2.charValue())) + ";";
assertEquals("hex number unescape index " + (int)i, expected, StringEscapeUtils.unescapeHtml4(escapedC1 + escapedC2));
}
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testUnescapeUnknownEntity() throws Exception {
assertEquals("&zzzz;", StringEscapeUtils.unescapeHtml4("&zzzz;"));
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testLang313() {
assertEquals("& &", StringEscapeUtils.unescapeHtml4("& &"));
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testUnescapeHtml4() {
for (final String[] element : HTML_ESCAPES) {
final String message = element[0];
final String expected = element[2];
final String original = element[1];
assertEquals(message, expected, StringEscapeUtils.unescapeHtml4(original));
final StringWriter sw = new StringWriter();
try {
StringEscapeUtils.UNESCAPE_HTML4.translate(original, sw);
} catch (final IOException e) {
}
final String actual = original == null ? null : sw.toString();
assertEquals(message, expected, actual);
}
// \u00E7 is a cedilla (c with wiggle under)
// note that the test string must be 7-bit-clean (Unicode escaped) or else it will compile incorrectly
// on some locales
assertEquals("funny chars pass through OK", "Fran\u00E7ais", StringEscapeUtils.unescapeHtml4("Fran\u00E7ais"));
assertEquals("Hello&;World", StringEscapeUtils.unescapeHtml4("Hello&;World"));
assertEquals("Hello&#;World", StringEscapeUtils.unescapeHtml4("Hello&#;World"));
assertEquals("Hello&# ;World", StringEscapeUtils.unescapeHtml4("Hello&# ;World"));
assertEquals("Hello&##;World", StringEscapeUtils.unescapeHtml4("Hello&##;World"));
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testEscapeHtmlVersions() throws Exception {
assertEquals("Β", StringEscapeUtils.escapeHtml4("\u0392"));
assertEquals("\u0392", StringEscapeUtils.unescapeHtml4("Β"));
// TODO: refine API for escaping/unescaping specific HTML versions
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* Tests // https://issues.apache.org/jira/browse/LANG-480
*/
@Test
public void testEscapeHtmlHighUnicode() {
// this is the utf8 representation of the character:
// COUNTING ROD UNIT DIGIT THREE
// in Unicode
// codepoint: U+1D362
final byte[] data = new byte[] { (byte)0xF0, (byte)0x9D, (byte)0x8D, (byte)0xA2 };
final String original = new String(data, Charset.forName("UTF8"));
final String escaped = StringEscapeUtils.escapeHtml4( original );
assertEquals( "High Unicode should not have been escaped", original, escaped);
final String unescaped = StringEscapeUtils.unescapeHtml4( escaped );
assertEquals( "High Unicode should have been unchanged", original, unescaped);
// TODO: I think this should hold, needs further investigation
// String unescapedFromEntity = StringEscapeUtils.unescapeHtml4( "𝍢" );
// assertEquals( "High Unicode should have been unescaped", original, unescapedFromEntity);
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* Tests https://issues.apache.org/jira/browse/LANG-339
*/
@Test
public void testEscapeHiragana() {
// Some random Japanese Unicode characters
final String original = "\u304B\u304C\u3068";
final String escaped = StringEscapeUtils.escapeHtml4(original);
assertEquals( "Hiragana character Unicode behaviour should not be being escaped by escapeHtml4",
original, escaped);
final String unescaped = StringEscapeUtils.unescapeHtml4( escaped );
assertEquals( "Hiragana character Unicode behaviour has changed - expected no unescaping", escaped, unescaped);
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testStandaloneAmphersand() {
assertEquals("<P&O>", StringEscapeUtils.unescapeHtml4("<P&O>"));
assertEquals("test & <", StringEscapeUtils.unescapeHtml4("test & <"));
assertEquals("<P&O>", StringEscapeUtils.unescapeXml("<P&O>"));
assertEquals("test & <", StringEscapeUtils.unescapeXml("test & <"));
}
代码示例来源:origin: loklak/loklak_server
if ((p = input.indexOf("data-reply-to-users-json=")) >= 0) {
prop mentions_prop = new prop(input, p, "data-reply-to-users-json");
String decoded = StringEscapeUtils.unescapeHtml4(mentions_prop.value);
JSONArray a = new JSONArray(new JSONTokener(decoded));
for (int i = 0; i < a.length(); i++) {
代码示例来源:origin: zhangxd1989/springboot-dubbox
@Override
public void serialize(String value, JsonGenerator jgen,
SerializerProvider provider) throws IOException {
jgen.writeString(StringEscapeUtils.unescapeHtml4(value));
}
}));
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testUnescapeSurrogatePairs() throws Exception {
assertEquals("\uD83D\uDE30", StringEscapeUtils.unescapeCsv("\uD83D\uDE30"));
// Examples from https://en.wikipedia.org/wiki/UTF-16
assertEquals("\uD800\uDC00", StringEscapeUtils.unescapeCsv("\uD800\uDC00"));
assertEquals("\uD834\uDD1E", StringEscapeUtils.unescapeCsv("\uD834\uDD1E"));
assertEquals("\uDBFF\uDFFD", StringEscapeUtils.unescapeCsv("\uDBFF\uDFFD"));
assertEquals("\uDBFF\uDFFD", StringEscapeUtils.unescapeHtml3("\uDBFF\uDFFD"));
assertEquals("\uDBFF\uDFFD", StringEscapeUtils.unescapeHtml4("\uDBFF\uDFFD"));
}
代码示例来源:origin: ron190/jsql-injection
result = StringEscapeUtils.unescapeHtml4(textInput).replace("<", "<").replace(">", ">");
代码示例来源:origin: chengzhx76/weixin-shop-spring-cloud
/**
* Html 解码
* @param htmlEscaped
* @return
*/
public static String unescapeHtml(String htmlEscaped) {
return StringEscapeUtils.unescapeHtml4(htmlEscaped);
}
代码示例来源:origin: jobxhub/JobX
/**
* Html 解码.
*/
public static String unescapeHtml(String htmlEscaped) {
return StringEscapeUtils.unescapeHtml4(htmlEscaped);
}
代码示例来源:origin: lcw2004/one
/**
* Html 解码.
*/
public static String unescapeHtml(String htmlEscaped) {
return StringEscapeUtils.unescapeHtml4(htmlEscaped);
}
代码示例来源:origin: com.quhaodian.discover/discover-user
/**
* Html 解码.
*/
public static String unescapeHtml(String htmlEscaped) {
return StringEscapeUtils.unescapeHtml4(htmlEscaped);
}
代码示例来源:origin: com.atlassian.confluence/confluence-webdriver-pageobjects
public String normalizeHtml(String html, boolean normalizeSpaces) {
// editorContent.setContentViaJs requires single quotes - replace non-escaped (not preceded by backslash) double quotes
html = html.replaceAll("(?<!\\\\)\"", "'");
// Why escape and unescape? Milter Reis: The reason for that is that firefox was having different return characters
// representations than chrome, and it was making assertions fail
StringBuilder buffer = new StringBuilder(unescapeHtml4(escapeHtml4(html)));
return normalizeSpaces ? buffer.toString().replace(" ", " ") : buffer.toString();
}
内容来源于网络,如有侵权,请联系作者删除!