本文整理了Java中org.apache.commons.lang3.StringEscapeUtils.unescapeEcmaScript()
方法的一些代码示例,展示了StringEscapeUtils.unescapeEcmaScript()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringEscapeUtils.unescapeEcmaScript()
方法的具体详情如下:
包路径:org.apache.commons.lang3.StringEscapeUtils
类名称:StringEscapeUtils
方法名:unescapeEcmaScript
[英]Unescapes any EcmaScript literals found in the String.
For example, it will turn a sequence of '' and 'n'into a newline character, unless the '' is preceded by another ''.
[中]取消扫描字符串中找到的任何EcmaScript文本。
例如,它会将“\”和“n”的序列转换为换行符,除非“\”前面有另一个“\”。
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testUnescapeEcmaScript() {
assertNull(StringEscapeUtils.escapeEcmaScript(null));
try {
StringEscapeUtils.UNESCAPE_ECMASCRIPT.translate(null, null);
fail();
} catch (final IOException ex) {
fail();
} catch (final IllegalArgumentException ex) {
}
try {
StringEscapeUtils.UNESCAPE_ECMASCRIPT.translate("", null);
fail();
} catch (final IOException ex) {
fail();
} catch (final IllegalArgumentException ex) {
}
assertEquals("He didn't say, \"stop!\"", StringEscapeUtils.unescapeEcmaScript("He didn\\'t say, \\\"stop!\\\""));
assertEquals("document.getElementById(\"test\").value = '<script>alert('aaa');</script>';",
StringEscapeUtils.unescapeEcmaScript("document.getElementById(\\\"test\\\").value = \\'<script>alert(\\'aaa\\');<\\/script>\\';"));
}
代码示例来源:origin: org.eclipse.dirigible/dirigible-api-utils
/**
* Unescape JavaScript.
*
* @param input
* the input
* @return the unescaped input
*/
public static final String unescapeJavascript(String input) {
return StringEscapeUtils.unescapeEcmaScript(input);
}
代码示例来源:origin: org.eclipse.dirigible/dirigible-api-facade-utils
/**
* Unescape JavaScript.
*
* @param input
* the input
* @return the unescaped input
*/
public static final String unescapeJavascript(String input) {
return StringEscapeUtils.unescapeEcmaScript(input);
}
代码示例来源:origin: apache/roller
public String unescapeJavaScript(String str) {
return StringEscapeUtils.unescapeEcmaScript(str);
}
代码示例来源:origin: xcesco/kripton
/**
* Extract as array of string.
*
* @param value the value
* @return the list
*/
public static List<String> extractAsArrayOfString(String value) {
Matcher matcher = arrayPattern.matcher(value);
List<String> result = new ArrayList<String>();
// we need to unscape javascript format, otherwise string like " where id like '%' " will become " where id like \'%\' "
while (matcher.find()) {
result.add(StringEscapeUtils.unescapeEcmaScript(matcher.group(1)));
}
return result;
}
代码示例来源:origin: apache/lens
@Override
public List<SavedQuery> handle(ResultSet resultSet) throws SQLException {
List<SavedQuery> queries = Lists.newArrayList();
while (resultSet.next()) {
long id = resultSet.getLong(ID_COL_NAME);
final String name = StringEscapeUtils.unescapeEcmaScript(resultSet.getString(NAME_COL_NAME));
final String description = StringEscapeUtils.unescapeEcmaScript(resultSet.getString(DESCRIPTION_COL_NAME));
final String query = StringEscapeUtils.unescapeEcmaScript(resultSet.getString(QUERY_COL_NAME));
final List<Parameter> parameterList;
try {
parameterList = deserializeFrom(
StringEscapeUtils.unescapeEcmaScript(resultSet.getString(PARAMS_COL_NAME))
);
} catch (LensException e) {
throw new SQLException("Cannot deserialize parameters ", e);
}
queries.add(new SavedQuery(
id,
name,
description,
query,
parameterList
));
}
return queries;
}
}
代码示例来源:origin: PennState/SCIMple-Identity
private static Object parseJsonType(String jsonValue) {
if (jsonValue.startsWith("\"")) {
String doubleEscaped = jsonValue.substring(1, jsonValue.length() - 1)
// StringEscapeUtils follows the outdated JSON spec requiring "/" to be escaped, this could subtly break things
.replaceAll("\\\\/", "\\\\\\\\/")
// Just in case someone needs a single-quote with a backslash in front of it, this will be unnecessary with escapeJson()
.replaceAll("\\\\'", "\\\\\\\\'");
// TODO change this to escapeJson() when dependencies get upgraded
return StringEscapeUtils.unescapeEcmaScript(doubleEscaped);
} else if ("null".equals(jsonValue)) {
return null;
} else if ("true".equals(jsonValue)) {
return true;
} else if ("false".equals(jsonValue)) {
return false;
} else {
try {
return Double.parseDouble(jsonValue);
} catch (NumberFormatException e) {
LOG.warn("Unable to parse a json number: " + jsonValue);
}
}
throw new IllegalStateException("Unable to parse JSON Value");
}
代码示例来源:origin: ssaarela/javersion
@Override
public PropertyPath visitKey(PropertyPathParser.KeyContext ctx) {
String keyLiteral = ctx.getText();
return parent = new Key(parent, unescapeEcmaScript(keyLiteral.substring(1, keyLiteral.length() - 1)));
}
代码示例来源:origin: org.xworker/xworker_core
public static String unescapeEcmaScript(ActionContext actionContext){
Thing self = actionContext.getObject("self");
String str = (String) self.doAction("getStr", actionContext);
return StringEscapeUtils.unescapeEcmaScript(str);
}
代码示例来源:origin: com.wuyushuo/vplus-core
if(StringUtils.isNotBlank(comment)){
comment = comment.replaceAll("\n","").replaceAll("\r", "");
comment = StringUtils.trim(StringEscapeUtils.unescapeEcmaScript(StringEscapeUtils.escapeHtml4(comment)));
field.setComment(comment);
代码示例来源:origin: org.wso2.org.apache.shindig/shindig-gadgets
@Test
public void testMultiPartFormPostWithSpecialChars() throws Exception {
String body = "\u003c!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\"\u003e"
+ "<html><body>"Hello, world!"</body></html>";
expectGetAndReturnBody(body);
expect(request.getParameter(MakeRequestHandler.CONTENT_TYPE_PARAM)).andReturn("TEXT");
expect(request.getParameter(MakeRequestHandler.MULTI_PART_FORM_POST_IFRAME)).andReturn("1");
replay();
handler.fetch(request, recorder);
String response = recorder.getResponseAsString();
response = StringUtils.removeStart(response, MakeRequestHandler.IFRAME_RESPONSE_PREFIX);
response = StringUtils.removeEnd(response, MakeRequestHandler.IFRAME_RESPONSE_SUFFIX);
response = StringEscapeUtils.unescapeEcmaScript(response);
JSONObject result = extractJsonFromResponse(response);
assertEquals(
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">"
+ "<html><body>"Hello, world!"</body></html>",
result.get("body")
);
}
代码示例来源:origin: org.apache.shindig/shindig-gadgets
@Test
public void testMultiPartFormPostWithSpecialChars() throws Exception {
String body = "\u003c!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\"\u003e"
+ "<html><body>"Hello, world!"</body></html>";
expectGetAndReturnBody(body);
expect(request.getParameter(MakeRequestHandler.CONTENT_TYPE_PARAM)).andReturn("TEXT");
expect(request.getParameter(MakeRequestHandler.MULTI_PART_FORM_POST_IFRAME)).andReturn("1");
replay();
handler.fetch(request, recorder);
String response = recorder.getResponseAsString();
response = StringUtils.removeStart(response, MakeRequestHandler.IFRAME_RESPONSE_PREFIX);
response = StringUtils.removeEnd(response, MakeRequestHandler.IFRAME_RESPONSE_SUFFIX);
response = StringEscapeUtils.unescapeEcmaScript(response);
JSONObject result = extractJsonFromResponse(response);
assertEquals(
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">"
+ "<html><body>"Hello, world!"</body></html>",
result.get("body")
);
}
代码示例来源:origin: com.github.cafdataprocessing/corepolicy-condition-engine
String unescaped = StringEscapeUtils.unescapeEcmaScript(policy.description);
ObjectNode objectNode = objectMapper.readValue(unescaped.substring(1, unescaped.length()-1),
ObjectNode.class);
内容来源于网络,如有侵权,请联系作者删除!