diff options
author | Maxime RETY <maximerety@macbook-de-maxime-rety.local> | 2010-06-14 16:05:49 +0200 |
---|---|---|
committer | Santiago Pastorino <santiago@wyeworks.com> | 2011-02-02 18:57:48 -0200 |
commit | 68e3fb81090ba67575e513407fc2463dba3b002b (patch) | |
tree | 39b1687fe614e9b57739bb6659d5e048e52151b6 /activesupport/lib/active_support | |
parent | 8bfa8e7cbea1fb65b180260c55a7f146efbd5b05 (diff) | |
download | rails-68e3fb81090ba67575e513407fc2463dba3b002b.tar.gz rails-68e3fb81090ba67575e513407fc2463dba3b002b.tar.bz2 rails-68e3fb81090ba67575e513407fc2463dba3b002b.zip |
Fix JSON decoding of newline character with Yaml backend [#3479 state:resolved]
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/json/backends/yaml.rb | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/json/backends/yaml.rb b/activesupport/lib/active_support/json/backends/yaml.rb index c7ed931c1b..b1dd2a8107 100644 --- a/activesupport/lib/active_support/json/backends/yaml.rb +++ b/activesupport/lib/active_support/json/backends/yaml.rb @@ -54,7 +54,9 @@ module ActiveSupport json.gsub(/\\([\\\/]|u[[:xdigit:]]{4})/) do ustr = $1 if ustr.start_with?('u') - [ustr[1..-1].to_i(16)].pack("U") + char = [ustr[1..-1].to_i(16)].pack("U") + # "\n" needs extra escaping due to yaml formatting + char == "\n" ? "\\n" : char elsif ustr == '\\' '\\\\' else @@ -75,7 +77,9 @@ module ActiveSupport chunk.gsub!(/\\([\\\/]|u[[:xdigit:]]{4})/) do ustr = $1 if ustr.start_with?('u') - [ustr[1..-1].to_i(16)].pack("U") + char = [ustr[1..-1].to_i(16)].pack("U") + # "\n" needs extra escaping due to yaml formatting + char == "\n" ? "\\n" : char elsif ustr == '\\' '\\\\' else |