Skip to content

Commit 7b9e9ee

Browse files
authored
Merge pull request rails#50489 from maniSHarma7575/50481-fix-activesupport-json-encode
[FIX] Fix Activesupport json encode for hash with duplicate keys
2 parents 590a675 + 94a4adb commit 7b9e9ee

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

activesupport/lib/active_support/json/encoding.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def jsonify(value)
7676
when Hash
7777
result = {}
7878
value.each do |k, v|
79-
k = k.to_s unless Symbol === k || String === k
79+
k = k.to_s unless String === k
8080
result[k] = jsonify(v)
8181
end
8282
result

activesupport/test/json/encoding_test_cases.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ module EncodingTestCases
8181
[ [1, "a", :b, nil, false], %([1,\"a\",\"b\",null,false]) ]]
8282

8383
HashTests = [[ { foo: "bar" }, %({\"foo\":\"bar\"}) ],
84-
[ { 1 => 1, 2 => "a", 3 => :b, 4 => nil, 5 => false }, %({\"1\":1,\"2\":\"a\",\"3\":\"b\",\"4\":null,\"5\":false}) ]]
84+
[ { 1 => 1, 2 => "a", 3 => :b, 4 => nil, 5 => false }, %({\"1\":1,\"2\":\"a\",\"3\":\"b\",\"4\":null,\"5\":false}) ],
85+
[ { "a" => 1, :a => 2, :c => { "b" => 3, :b => 4 } }, %({\"a\":2,\"c\":{\"b\":4}}) ]]
8586

8687
RangeTests = [[ 1..2, %("1..2")],
8788
[ 1...2, %("1...2")],

0 commit comments

Comments
 (0)