Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

StringEscapeUtils find out if string is escaped

I've been using StringEscapeUtils.escapeHTML to escape URLs. Is there something similar to find out if the string is already escaped?

like image 539
ricardoespsanto Avatar asked Mar 15 '26 03:03

ricardoespsanto


2 Answers

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.

like image 96
themel Avatar answered Mar 16 '26 17:03

themel


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.

like image 39
Keppil Avatar answered Mar 16 '26 18:03

Keppil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!