Skip to content
This repository
Browse code

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...
commit 9e4efed6e0c3fde2944b01e558a61d5b7a188d21 2 parents dae66a0 + 1fb7969
Jeremy Kemper authored October 30, 2013
4  activesupport/CHANGELOG.md
Source Rendered
... ...
@@ -1,3 +1,7 @@
  1
+*   Calling ActiveSupport::JSON.decode with unsupported options now raises an error.
  2
+
  3
+    *Godfrey Chan*
  4
+
1 5
 *   Support :unless_exist in FileStore
2 6
 
3 7
     *Michael Grosser*
9  activesupport/lib/active_support/json/decoding.rb
@@ -14,7 +14,14 @@ class << self
14 14
       #   ActiveSupport::JSON.decode("{\"team\":\"rails\",\"players\":\"36\"}")
15 15
       #   => {"team" => "rails", "players" => "36"}
16 16
       def decode(json, options = {})
17  
-        data = ::JSON.parse(json, options.merge(create_additions: false, quirks_mode: true))
  17
+        if options.present?
  18
+          raise ArgumentError, "In Rails 4.1, ActiveSupport::JSON.decode no longer " \
  19
+            "accepts an options hash for MultiJSON. MultiJSON reached its end of life " \
  20
+            "and has been removed."
  21
+        end
  22
+
  23
+        data = ::JSON.parse(json, quirks_mode: true)
  24
+
18 25
         if ActiveSupport.parse_json_times
19 26
           convert_dates_from(data)
20 27
         else
6  activesupport/test/json/decoding_test.rb
@@ -98,10 +98,8 @@ def test_failed_json_decoding
98 98
     assert_raise(ActiveSupport::JSON.parse_error) { ActiveSupport::JSON.decode(%()) }
99 99
   end
100 100
 
101  
-  def test_cannot_force_json_unmarshalling
102  
-    encodeded = %q({"json_class":"TestJSONDecoding::Foo"})
103  
-    decodeded = {"json_class"=>"TestJSONDecoding::Foo"}
104  
-    assert_equal decodeded, ActiveSupport::JSON.decode(encodeded, create_additions: true)
  101
+  def test_cannot_pass_unsupported_options
  102
+    assert_raise(ArgumentError) { ActiveSupport::JSON.decode("", create_additions: true) }
105 103
   end
106 104
 end
107 105
 

0 notes on commit 9e4efed

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