Alternative to using StringEscapeUtils.escapeJavaScript() in commons lang3
Solution 1
Either of escapeEcmaScript
or escapeJson
would be a suitable replacement.
Solution 2
According to the Apache Commons deprecated page, we should be using:
- Apache Commons Text
- StringEscapeUtils
- for Maven/Gradle: 'org.apache.commons:commons-text:'
Related videos on Youtube
Popeye
Interesting http://meta.stackexchange.com/questions/182266/how-much-research-effort-is-expected-of-stack-overflow-users/182380#182380 Consider reading before asking a question University: BSc (Hons) Computing
Updated on April 05, 2022Comments
-
Popeye about 2 years
I've been tasked with updating our code from using
org.apache.commons.lang
toorg.apache.commons.lang3
and I've found that the newer version ofStringEscapeUtils
no longer has the methodescapeJavaScript()
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 forlang3
(see release notes lang 3.3.2) and with this rewrite they removedescapeJavaScript()
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()
?-
Popeye about 9 yearsIt would be interesting to know why someone thinks this is off-topic because it is asking FOR off-site resources and why they think it should be closed. I'm not asking for off-site resources I have the resource it's
commons lang3
I'm asking for an alternative work around to replace that ofescapeJavaScript
and whether there is an alternative held within thecommons lang3
code itself. Please detail why you believe this is off-topic -
Jeremy Goodell over 8 yearsThanks for asking this. I discovered the same thing today and couldn't find any reference to it in the commons doc.
-
-
Popeye about 9 yearsDoing a little digging into the
escapeEcmaScript
I've found that essentially when they re-wrote theStringEscapeUtils
class they decided to give it a name change as essentially the method was changing to cover all the ECMA standard Languages such asJScript
,JavaScript
andActionScript
so I believe changing it to use theescapeEcmaScript
is the correct approach. So +1 and accepted. Thanks