ActiveSupport::JSON.decode 无法正确处理文字换行符

2024-04-01

这是预期的行为吗?请注意换行符是如何丢失的。

ruby-1.9.2-p136 :001 > ActiveSupport::JSON.decode("{\"content\": \"active\n\nsupport\"}")
 => {"content"=>"active\nsupport"}

对于 unicode 转义换行符也会发生同样的情况:

ruby-1.9.2-p136 :002 > ActiveSupport::JSON.decode("{\"content\": \"active\u000a\u000asupport\"}")
 => {"content"=>"active\nsupport"}

我正在使用 Rails 3.0.3。


我最终发现了这张票:https://rails.lighthouseapp.com/projects/8994/tickets/3479-activesupportjson-fails-to-decode-unicode-escaped-newline-and-literal-newlines https://rails.lighthouseapp.com/projects/8994/tickets/3479-activesupportjson-fails-to-decode-unicode-escaped-newline-and-literal-newlines

看来这是 ActiveSupport 中的一个错误,将在 Rails 3.0.5 中修复。现在我有修补主动支持 https://github.com/rails/rails/commit/68e3fb81090ba67575e513407fc2463dba3b002b一切都按预期进行。

ruby-1.9.2-p136 :001 > ActiveSupport::JSON.decode("{\"content\": \"active\n\nsupport\"}")
 => {"content"=>"active\n\nsupport"}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ActiveSupport::JSON.decode 无法正确处理文字换行符 的相关文章

随机推荐