Skip to content

Commit 9e4efed

Browse files
committed
Merge pull request rails#12214 from chancancode/json_decode_does_not_take_options
Raise an error when AS::JSON.decode is called with options
2 parents dae66a0 + 1fb7969 commit 9e4efed

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

activesupport/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Calling ActiveSupport::JSON.decode with unsupported options now raises an error.
2+
3+
*Godfrey Chan*
4+
15
* Support :unless_exist in FileStore
26

37
*Michael Grosser*

activesupport/lib/active_support/json/decoding.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ class << self
1414
# ActiveSupport::JSON.decode("{\"team\":\"rails\",\"players\":\"36\"}")
1515
# => {"team" => "rails", "players" => "36"}
1616
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+
1825
if ActiveSupport.parse_json_times
1926
convert_dates_from(data)
2027
else

activesupport/test/json/decoding_test.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,8 @@ def test_failed_json_decoding
9898
assert_raise(ActiveSupport::JSON.parse_error) { ActiveSupport::JSON.decode(%()) }
9999
end
100100

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) }
105103
end
106104
end
107105

0 commit comments

Comments
 (0)