开发者

Ruby on Rails: How best to escape a string in a model?

开发者 https://www.devze.com 2022-12-30 21:49 出处:网络
I want my application to sanitize html on input rather than on display, so that the fields saved into the database are sanitized.

I want my application to sanitize html on input rather than on display, so that the fields saved into the database are sanitized.

I've been doing this with strip_tags, and it was working great. However, this has the downside that it means the user can't input anything that's bracketed with < and >.

How ca开发者_如何转开发n I tell Rails in the model to securely escape tags before saving them to the database? I'd like to not have to call h on the sanitized fields again before using them in the views.


You could call the h method in a before_save filter.


One option is to use the plugin xss_terminate: http://code.google.com/p/xssterminate/

By default it strips all HTML tags from user input.

0

精彩评论

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