Skip to content

Commit

Permalink
Reverted affe501 and added more JSON decoding tests.
Browse files Browse the repository at this point in the history
Works on Ruby 1.8 and 1.9

[#1100 state:resolved]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information
Bira authored and jeremy committed Mar 11, 2009
1 parent f2c7508 commit 7b382cb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 10 additions & 1 deletion activesupport/lib/active_support/json/decoding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,16 @@ def convert_json_to_yaml(json) #:nodoc:
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 * " "

Expand Down
4 changes: 3 additions & 1 deletion activesupport/test/json/decoding_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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") => "<unicode escape>",
%q("\\\\u0020skip double backslashes") => "\\u0020skip double backslashes"
%q("\\\\u0020skip double backslashes") => "\\u0020skip double backslashes",
%q({a: "\u003cbr /\u003e"}) => {'a' => "<br />"},
%q({b:["\u003ci\u003e","\u003cb\u003e","\u003cu\u003e"]}) => {'b' => ["<i>","<b>","<u>"]}
}

TESTS.each do |json, expected|
Expand Down

0 comments on commit 7b382cb

Please sign in to comment.