您现在的位置是:首页 > 文章详情

escape in ABAP and JavaScript

日期:2020-02-29点击:698

ABAP

IF_HTTP_UTILITY~ESCAPE_URL

JavaScript

开源的sanitizer库,Google搞的。

https://www.npmjs.com/package/sanitizer
sanitizer.escape('your dirty string');
用于C4C:

在Java里使用这个JS library:

public class CajaSanitiser { private final ScriptEngine engine; private final Bindings bindings; public CajaSanitiser() throws IOException, ScriptException { this.engine = new ScriptEngineManager().getEngineByName("js"); this.bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE); String scriptName = "com/google/caja/plugin/html-css-sanitizer-minified.js"; try (BufferedReader reader = getReader(scriptName)) { engine.eval(reader); } String identity = "function identity(value) {return value;}"; engine.eval(identity); } private BufferedReader getReader(String name) { return new BufferedReader(new InputStreamReader( getClass().getClassLoader().getResourceAsStream(name))); } public String sanitise(String htmlSource) throws ScriptException { bindings.put("src", htmlSource); // You can use other functions beside 'identity' if you // want to transform the html. // See https://code.google.com/p/google-caja/wiki/JsHtmlSanitizer return (String) engine.eval("html_sanitize(src, identity, identity)"); } public static void main(String[] args) throws Exception { CajaSanitiser sanitiser = new CajaSanitiser(); String source = "<html>\n" + "<head>\n" + "<style>\n" + "h1 {color:blue;}\n" + "</style>\n" + "</head>\n" + "<body>\n" + "<h1>A heading</h1>\n" + "</body>\n" + "</html>"; System.out.println("Original HTML with CSS:"); System.out.println(source); System.out.println(); System.out.println("Sanitised HTML:"); System.out.println(sanitiser.sanitise(source)); } }

Maven dependency:

<dependencies> <dependency> <groupId>caja</groupId> <artifactId>caja</artifactId> <version>r5127</version> </dependency> </dependencies>

本文来自云栖社区合作伙伴“汪子熙”,了解相关信息可以关注微信公众号"汪子熙"。

原文链接:https://yq.aliyun.com/articles/747352
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章