现在的项目使用了 cell 这个 gem
https://github.com/trailblazer/cells
在 4.0 以前的时候使用的是 rails 的 render,默认会进行 html escape
比如下面的代码是没有问题的
@text = '<script>alert("hello")</script>'
<%= @text %>
目前打算升级到 4.0
但是 4.0 以后,cell 采用了其他的 render 方法,默认不进行 html escape, 必须像下面这样传递 escape 过后的值
@text = '<script>alert("hello")</script>'
<%= h @text %>
http://trailblazer.to/gems/cells/cells4.html
Cells per default does not escape HTML. However, you may run into problems when using Rails helpers. Internally, those helpers often blindly escape. This is not Cells’ fault but a design flaw in Rails. Everything related to #capture will cause problems - check this as an example. As you can see, this is Rails swinging the escape hammer. Please don’t blame us for escapes where they shouldn’t be. Rather open an issue on Rails and tell them to make their code better overrideable for us.
但是每个字段自己写代码 escape 感觉很麻烦,而且万一忘记了,会出现安全问题
目前把需要 escape 的都加了 html_escape 方法暂时对应了 (估计有漏的地方)
没找到其他的好的方法,有遇到相同的问题的吗?