开发者

Java library that escapes quotation marks

I often have to escape many quotation marks in a String. Is there a library that provides String functions such as this. It's easy enough to write, but something that had lots of 开发者_开发百科different features/options for escaping would be handy.


Apache Commons has a StringEscapeUtils class which is able to escape (and unescape) in the following formats:

  • CSV
  • HTML
  • Java
  • JavaScript
  • SQL
  • XML


It depends on the context in which you're escaping the quotation marks. Usually, it should be handled by a task-specific library. For example, if you're escaping quotes for use in an SQL string, you should be using parameter placeholders instead of concatenating the string. If you're escaping quotes for use in a JSP, you should use <c:out> which will deal with quotes and other HTML entities.


You can use OWASP's Enterprise Security API (Java Edition)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜