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

JSON.dump inconsistent output for hash #563

Open
maniSHarma7575 opened this issue Dec 31, 2023 · 0 comments · May be fixed by #564
Open

JSON.dump inconsistent output for hash #563

maniSHarma7575 opened this issue Dec 31, 2023 · 0 comments · May be fixed by #564

Comments

@maniSHarma7575
Copy link

Steps to reproduce

require "minitest/autorun"
require "json"


class DumpTest < Minitest::Test
  def test_dump_duplicate_key_hash
    assert_equal "{\"a\":5,\"c\":{\"b\":6}}", JSON.dump({ 'a' => 1,  a: 5, c: { 'b' => 2, b: 6 } })
  end
end

Expected behaviour

Test case should pass

Actual behavior

Run options: --seed 18012

# Running:

F

Failure:
DumpTest#test_dump_duplicate_key_hash [nano-example.rb:7]:
--- expected
+++ actual
@@ -1 +1 @@
-"{\"a\":5,\"c\":{\"b\":6}}"
+"{\"a\":1,\"a\":5,\"c\":{\"b\":2,\"b\":6}}"



bin/rails test nano-example.rb:6



Finished in 0.007499s, 133.3511 runs/s, 133.3511 assertions/s.
1 runs, 1 assertions, 1 failures, 0 errors, 0 skips

System configuration

Ruby version: ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23], ruby 3.2.0, ruby 2.7.8

Same issue got reported in Rails ActiveSupport encode as well. Check it out here: #50481

cc: @byroot @hsbt

@maniSHarma7575 maniSHarma7575 linked a pull request Dec 31, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant