java 在 commons lang3 中使用 StringEscapeUtils.escapeJavaScript() 的替代方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29146341/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 14:45:24  来源:igfitidea点击:

Alternative to using StringEscapeUtils.escapeJavaScript() in commons lang3

javaapache-commons-langapache-commons-lang3

提问by Popeye

I've been tasked with updating our code from using org.apache.commons.langto org.apache.commons.lang3and I've found that the newer version of StringEscapeUtilsno longer has the method escapeJavaScript()however we were using this in quite a few places throughout our code.

我一直在负责使用更新我们的代码org.apache.commons.langorg.apache.commons.lang3和我发现,新版本StringEscapeUtils不再有法escapeJavaScript()但我们是在我们整个代码不少地方用这个。

I've been reading through the documentation and it seems that the whole of StringEscapeUtilswas rewritten for lang3(see release notes lang 3.3.2) and with this rewrite they removed escapeJavaScript()however they haven't said what to use as an alternative in any of their documentation (Not that I can see anyway). Here's the what's new documentation.

我一直在阅读文档,似乎整个都StringEscapeUtils被重写了lang3参见发行说明 lang 3.3.2)并且通过这次重写他们删除了escapeJavaScript()但是他们没有说在他们的任何文档中使用什么作为替代(无论如何我都看不到)。这是新文档

So my question is I can't be the only one to have noticed this and experienced this issue so what is the alternative to using StringEscapeUtils.escapeJavaScript()?

所以我的问题是我不可能是唯一一个注意到这一点并经历过这个问题的人,那么使用 的替代方法是StringEscapeUtils.escapeJavaScript()什么?

回答by Ian Roberts

Either of escapeEcmaScriptor escapeJsonwould be a suitable replacement.

任一的escapeEcmaScriptescapeJson将是一个合适的替代。

回答by will

According to the Apache Commons deprecated page, we should be using:

根据 Apache Commons deprecated 页面,我们应该使用:

  • Apache Commons Text