Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Pretty generation produces incorrect indentation with 2.11.x #790

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

Closed
Bo98 opened this issue Apr 25, 2025 · 2 comments · Fixed by #791
Closed

Pretty generation produces incorrect indentation with 2.11.x #790

Bo98 opened this issue Apr 25, 2025 · 2 comments · Fixed by #791

Comments

@Bo98
Copy link

Bo98 commented Apr 25, 2025

Using:

ruby 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [arm64-darwin23]

Test script:

require "json"
require "uri"

test = {
  a: {
    b: URI("https://example.com"),
  },
  c: "d",
}
puts JSON.pretty_generate(test)

Output with 2.10.2:

$ cat Gemfile
source "https://rubygems.org"

gem "json", "=2.10.2"
$ bundle exec ruby test.rb
{
  "a": {
    "b": "https://example.com"
  },
  "c": "d"
}

Output with 2.11.2:

$ cat Gemfile             
source "https://rubygems.org"

gem "json", "=2.11.2"
$ bundle exec ruby test.rb
{
  "a": {
    "b": "https://example.com"
  },
    "c": "d"
}

Above example was trying to give a real-world use case (URIs). A simpler example for an rspec would be something like:

require "json"

class A
  def to_s = "value"
end
   
test = {
  a: {  
    b: A.new,
  },
  c: "d",
}
puts JSON.pretty_generate(test)
$ bundle exec ruby test.rb
{
  "a": {
    "b": "value"
  },
    "c": "d"
}
@byroot
Copy link
Member

byroot commented Apr 25, 2025

Thanks you for the report. I'm able to reproduce, I'll figure out a fix.

byroot added a commit to byroot/json that referenced this issue Apr 25, 2025
Fix: ruby#790

If we end up calling something that spills the state
on the heap, the pointer we received is outdated and
may be out of sync.
byroot added a commit to byroot/json that referenced this issue Apr 25, 2025
Fix: ruby#790

If we end up calling something that spills the state
on the heap, the pointer we received is outdated and
may be out of sync.
@byroot
Copy link
Member

byroot commented Apr 25, 2025

2.11.3 is out with the fix.

byroot added a commit to byroot/ruby that referenced this issue Apr 28, 2025
Fix: ruby/json#790

If we end up calling something that spills the state
on the heap, the pointer we received is outdated and
may be out of sync.

ruby/json@2ffa4ea46b
byroot added a commit to byroot/ruby that referenced this issue Apr 28, 2025
Fix: ruby/json#790

If we end up calling something that spills the state
on the heap, the pointer we received is outdated and
may be out of sync.

ruby/json@2ffa4ea46b
byroot added a commit to byroot/ruby that referenced this issue Apr 29, 2025
Fix: ruby/json#790

If we end up calling something that spills the state
on the heap, the pointer we received is outdated and
may be out of sync.

ruby/json@2ffa4ea46b
byroot added a commit to ruby/ruby that referenced this issue Apr 30, 2025
Fix: ruby/json#790

If we end up calling something that spills the state
on the heap, the pointer we received is outdated and
may be out of sync.

ruby/json@2ffa4ea46b
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.

2 participants