开发者

Java library that escapes quotation marks

开发者 https://www.devze.com 2023-03-10 16:19 出处:网络
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 开发者_开发百科diffe

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

精彩评论

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