我想用html& css in form.text_area:text
<%= sanitize @post.text , tags: %w(table tr td div p span img), attributes: %w(id class style src) %>
但是css attr“style”不适用于background-image。
<div style="color:red; background-image: url('http://tra-ta-ta.com/1.jpg')">
text
</div>
图片不起作用。我如何使用背景图像?
sanitize.rb中的问题
def sanitize_css(style) # disallow urls style = style.to_s.gsub(/url\s*\(\s*[^\s)]+?\s*\)\s*/, ' ')
答案 0 :(得分:0)
样式属性中的URL字符串“url(...)”强制替换为默认清理程序HTML::WhiteListSanitizer
的“”。您可以实现自己的清理程序,并让Rails通过编辑config / application.rb来使用它。
config.action_view.white_list_sanitizer = MySpecialSanitizer.new
检查ActionPack中的以下文件以获取更多信息:
actionpack-x.x.x/lib/action_view/helpers/sanitize_helper.rb
actionpack-x.x.x/lib/action_controller/vendor/html-scanner/html/sanitizer.rb
答案 1 :(得分:-1)
我只使用raw而不消毒