【发布时间】:2015-08-31 19:08:49
【问题描述】:
这就是rails console (Rails v4.0.4) 中发生的情况:
irb(main):020:0> "pepe&pepe <juan>".to_json
=> "\"pepe\\u0026pepe \\u003Cjuan\\u003E\""
这就是irb console (Ruby 2.0.0p247) 中发生的情况:
irb(main):014:0> "pepe&pepe <juan>".to_json
=> "\"pepe&pepe <juan>\""
我知道我可以覆盖此行为,但我担心的是为什么 Rails 默认会这样做?这可能是不这样做的后果?因为对我来说,覆盖这种行为而不是转义 html 实体看起来是个好主意,但我确信我错过了一些东西。
【问题讨论】:
标签: ruby-on-rails ruby json escaping