ActiveSupport::JSON.decode 无法正确处理文字换行符 [英] ActiveSupport::JSON.decode does not properly handle literal line breaks

查看:66
本文介绍了ActiveSupport::JSON.decode 无法正确处理文字换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is this the expected behavior? Note how the line break character gets lost.

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

Unicode 转义的换行符也会发生同样的情况:

The same happens with unicode-escaped line breaks:

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

我使用的是 rails 3.0.3.

I'm using rails 3.0.3.

推荐答案

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

这似乎是 ActiveSupport 中的一个错误,将在 Rails 3.0.5 中修复.现在我已经修补了 activesupport 并且一切按预期工作.

It seems this is a bug in ActiveSupport that will be fixed in Rails 3.0.5. For now I have patched activesupport and things are working as expected.

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

这篇关于ActiveSupport::JSON.decode 无法正确处理文字换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆