Permalink
Browse files

Merge pull request #12214 from chancancode/json_decode_does_not_take_…

…options

Raise an error when AS::JSON.decode is called with options
  • Loading branch information...
2 parents dae66a0 + 1fb7969 commit 9e4efed6e0c3fde2944b01e558a61d5b7a188d21 @jeremy jeremy committed Oct 30, 2013
@@ -1,3 +1,7 @@
+* Calling ActiveSupport::JSON.decode with unsupported options now raises an error.
+
+ *Godfrey Chan*
+
* Support :unless_exist in FileStore
*Michael Grosser*
@@ -14,7 +14,14 @@ class << self
# ActiveSupport::JSON.decode("{\"team\":\"rails\",\"players\":\"36\"}")
# => {"team" => "rails", "players" => "36"}
def decode(json, options = {})
- data = ::JSON.parse(json, options.merge(create_additions: false, quirks_mode: true))
+ if options.present?
+ raise ArgumentError, "In Rails 4.1, ActiveSupport::JSON.decode no longer " \
+ "accepts an options hash for MultiJSON. MultiJSON reached its end of life " \
+ "and has been removed."
+ end
+
+ data = ::JSON.parse(json, quirks_mode: true)
+
if ActiveSupport.parse_json_times
convert_dates_from(data)
else
@@ -98,10 +98,8 @@ def test_failed_json_decoding
assert_raise(ActiveSupport::JSON.parse_error) { ActiveSupport::JSON.decode(%()) }
end
- def test_cannot_force_json_unmarshalling
- encodeded = %q({"json_class":"TestJSONDecoding::Foo"})
- decodeded = {"json_class"=>"TestJSONDecoding::Foo"}
- assert_equal decodeded, ActiveSupport::JSON.decode(encodeded, create_additions: true)
+ def test_cannot_pass_unsupported_options
+ assert_raise(ArgumentError) { ActiveSupport::JSON.decode("", create_additions: true) }
end
end

0 comments on commit 9e4efed

Please sign in to comment.