From 01136e875e331809278cb2b0fbf5f7a8382e37d6 Mon Sep 17 00:00:00 2001 From: Ubiratan Pires Alberton Date: Wed, 11 Mar 2009 06:12:08 -0300 Subject: [PATCH] Reverted affe50105f7027a44eb6e9cfb56f5b3fc070b19b and added more JSON decoding tests. Works on Ruby 1.8 and 1.9 --- activesupport/lib/active_support/json/decoding.rb | 11 ++++++++++- activesupport/test/json/decoding_test.rb | 4 +++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/activesupport/lib/active_support/json/decoding.rb b/activesupport/lib/active_support/json/decoding.rb index 198f3fd..0e07934 100644 --- a/activesupport/lib/active_support/json/decoding.rb +++ b/activesupport/lib/active_support/json/decoding.rb @@ -59,7 +59,16 @@ module ActiveSupport output = [] left_pos.each_with_index do |left, i| scanner.pos = left.succ - output << scanner.peek(right_pos[i] - scanner.pos + 1) + output << scanner.peek(right_pos[i] - scanner.pos + 1).gsub(/\\([\\\/]|u[[:xdigit:]]{4})/) do + ustr = $1 + if ustr.starts_with?('u') + [ustr[1..-1].to_i(16)].pack("U") + elsif ustr == '\\' + '\\\\' + else + ustr + end + end end output = output * " " diff --git a/activesupport/test/json/decoding_test.rb b/activesupport/test/json/decoding_test.rb index c5816ea..8fe4055 100644 --- a/activesupport/test/json/decoding_test.rb +++ b/activesupport/test/json/decoding_test.rb @@ -30,7 +30,9 @@ class TestJSONDecoding < Test::Unit::TestCase %(false) => false, %q("http:\/\/test.host\/posts\/1") => "http://test.host/posts/1", %q("\u003cunicode\u0020escape\u003e") => "", - %q("\\\\u0020skip double backslashes") => "\\u0020skip double backslashes" + %q("\\\\u0020skip double backslashes") => "\\u0020skip double backslashes", + %q({a: "\u003cbr /\u003e"}) => {'a' => "
"}, + %q({b:["\u003ci\u003e","\u003cb\u003e","\u003cu\u003e"]}) => {'b' => ["","",""]} } TESTS.each do |json, expected| -- 1.6.2