Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed failing JSON decoding in rails 3-0-stable #9126

Merged
merged 1 commit into from Feb 11, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion activesupport/lib/active_support/json/backends/jsongem.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def decode(json)
if json.respond_to?(:read) if json.respond_to?(:read)
json = json.read json = json.read
end end
data = ::JSON.parse(json) data = ::JSON.load(json)
if ActiveSupport.parse_json_times if ActiveSupport.parse_json_times
convert_dates_from(data) convert_dates_from(data)
else else
Expand Down
1 change: 1 addition & 0 deletions activesupport/lib/active_support/json/backends/okjson.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def textparse(ts)


typ, _, val = ts[0] typ, _, val = ts[0]
case typ case typ
when :str, :val then valparse(ts)
when '{' then objparse(ts) when '{' then objparse(ts)
when '[' then arrparse(ts) when '[' then arrparse(ts)
else else
Expand Down
11 changes: 10 additions & 1 deletion activesupport/test/json/decoding_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ class TestJSONDecoding < ActiveSupport::TestCase
# tests escaping of "\n" char with Yaml backend # tests escaping of "\n" char with Yaml backend
%q({"a":"\n"}) => {"a"=>"\n"}, %q({"a":"\n"}) => {"a"=>"\n"},
%q({"a":"\u000a"}) => {"a"=>"\n"}, %q({"a":"\u000a"}) => {"a"=>"\n"},
%q({"a":"Line1\u000aLine2"}) => {"a"=>"Line1\nLine2"} %q({"a":"Line1\u000aLine2"}) => {"a"=>"Line1\nLine2"},
"\"foobar\"" => "foobar",
"42" => 42,
"null" => nil
} }


# load the default JSON backend # load the default JSON backend
Expand Down Expand Up @@ -87,5 +90,11 @@ class TestJSONDecoding < ActiveSupport::TestCase
def test_failed_json_decoding def test_failed_json_decoding
assert_raise(ActiveSupport::JSON.parse_error) { ActiveSupport::JSON.decode(%({: 1})) } assert_raise(ActiveSupport::JSON.parse_error) { ActiveSupport::JSON.decode(%({: 1})) }
end end

def test_decoding_of_json_encoded_string
assert_equal "foobar", ActiveSupport::JSON.decode(ActiveSupport::JSON.encode("foobar"))
assert_equal 42, ActiveSupport::JSON.decode(ActiveSupport::JSON.encode(42))
assert_equal nil, ActiveSupport::JSON.decode(ActiveSupport::JSON.encode(nil))
end
end end