I've been using StringEscapeUtils.escapeHTML to escape URLs. Is there something similar to find out if the string is already escaped?
This is impossible in principle, since every escaped string is at the same time an unescaped string, e.g. "a>b" could be both an escaped version of "a>b" or simply the literal string "a>b" before escaping.
Not that I know of, but it is pretty easy to do one yourself:
public boolean isEscaped(String url) {
return !url.equals(StringEscapeUtils.unEscapeHTML(url));
}
Note that deciding if a random string is escaped or not is impossible as @themel notes, you can get a lot of false positives if you try this with random strings. However I'm assuming that you at least have some control over what your strings look like here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With