Alternative to using StringEscapeUtils.escapeJavaScript() in commons lang3

19,040

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
Share:
19,040

Related videos on Youtube

Popeye
Author by

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, 2022

Comments

  • Popeye
    Popeye about 2 years

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

    • Popeye
      Popeye about 9 years
      It 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 of escapeJavaScript and whether there is an alternative held within the commons lang3 code itself. Please detail why you believe this is off-topic
    • Jeremy Goodell
      Jeremy Goodell over 8 years
      Thanks for asking this. I discovered the same thing today and couldn't find any reference to it in the commons doc.
  • Popeye
    Popeye about 9 years
    Doing a little digging into the escapeEcmaScript I've found that essentially when they re-wrote the StringEscapeUtils class they decided to give it a name change as essentially the method was changing to cover all the ECMA standard Languages such as JScript, JavaScript and ActionScript so I believe changing it to use the escapeEcmaScript is the correct approach. So +1 and accepted. Thanks