StringEscapeUtils找出是否转义了字符串 [英] StringEscapeUtils find out if string is escaped

查看:121
本文介绍了StringEscapeUtils找出是否转义了字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用StringEscapeUtils.escapeHTML来转义URL。是否有类似的东西,以确定字符串是否已经被转义?

解决方案

不是我所知道的,但是很容易自己做一个:

  public boolean isEscaped(String url){
return!url.equals(StringEscapeUtils.unEscapeHTML(url));
}

注意,决定随机字符串是否被转义是不可能的@themel注意,如果您尝试使用随机字符串,您可以得到很多假阳性。不过我假设你至少有一些控制你的字符串看起来像这里。


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

解决方案

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.

这篇关于StringEscapeUtils找出是否转义了字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆