Alternative to using StringEscapeUtils.escapeJavaScript() in commons lang3

别来无恙 提交于 2019-12-06 17:09:31

问题


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

I've been reading through the documentation and it seems that the whole of StringEscapeUtils was 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.

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()?


回答1:


Either of escapeEcmaScript or escapeJson would be a suitable replacement.




回答2:


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

  • Apache Commons Text
    • StringEscapeUtils
    • for Maven/Gradle: 'org.apache.commons:commons-text:'


来源:https://stackoverflow.com/questions/29146341/alternative-to-using-stringescapeutils-escapejavascript-in-commons-lang3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!