Skip to content
This repository
Browse code

Reverted affe501 and added more JSON decoding tests.

Works on Ruby 1.8 and 1.9

[#1100 state:resolved]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information...
commit 7b382cb9e5c5706f8d15216159a2873375915c9c 1 parent f2c7508
Ubiratan Pires Alberton authored jeremy committed
11  activesupport/lib/active_support/json/decoding.rb
@@ -59,7 +59,16 @@ def convert_json_to_yaml(json) #:nodoc:
59 59
             output    = []
60 60
             left_pos.each_with_index do |left, i|
61 61
               scanner.pos = left.succ
62  
-              output << scanner.peek(right_pos[i] - scanner.pos + 1)
  62
+              output << scanner.peek(right_pos[i] - scanner.pos + 1).gsub(/\\([\\\/]|u[[:xdigit:]]{4})/) do
  63
+                ustr = $1
  64
+                if ustr.starts_with?('u')
  65
+                  [ustr[1..-1].to_i(16)].pack("U")
  66
+                elsif ustr == '\\'
  67
+                '\\\\'
  68
+                else
  69
+                  ustr
  70
+                end
  71
+              end
63 72
             end
64 73
             output = output * " "
65 74
             
4  activesupport/test/json/decoding_test.rb
@@ -30,7 +30,9 @@ class TestJSONDecoding < Test::Unit::TestCase
30 30
     %(false) => false,
31 31
     %q("http:\/\/test.host\/posts\/1") => "http://test.host/posts/1",
32 32
     %q("\u003cunicode\u0020escape\u003e") => "<unicode escape>",
33  
-    %q("\\\\u0020skip double backslashes") => "\\u0020skip double backslashes"
  33
+    %q("\\\\u0020skip double backslashes") => "\\u0020skip double backslashes",
  34
+    %q({a: "\u003cbr /\u003e"}) => {'a' => "<br />"},
  35
+    %q({b:["\u003ci\u003e","\u003cb\u003e","\u003cu\u003e"]}) => {'b' => ["<i>","<b>","<u>"]}
34 36
   }
35 37
   
36 38
   TESTS.each do |json, expected|

0 notes on commit 7b382cb

Please sign in to comment.
Something went wrong with that request. Please try again.