Project

General

Profile

Actions

Bug #16250

closed

IRB can't print recursive Arrays or Hashes

Added by the-asterite (Ary Borenszweig) about 5 years ago. Updated about 5 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.7.0dev (2019-06-04 trunk 4b7213a85a) [x86_64-darwin18]
[ruby-core:95318]

Description

This is on Ruby 2.7.0dev but I'm almost sure it happens on master because this code has no check for recursion: https://github.com/ruby/ruby/blob/c3a626030235c0349e14c6bc07177810daee841c/lib/irb/color.rb#L73-L88

Code to reproduce:

$ irb
irb(main):001:0> a = []
=> []
irb(main):002:0> a << a
Traceback (most recent call last):
       16: from /Users/asterite/.rbenv/versions/2.7.0-dev/lib/ruby/2.7.0/irb/color.rb:80:in `all?'
       15: from /Users/asterite/.rbenv/versions/2.7.0-dev/lib/ruby/2.7.0/irb/color.rb:80:in `block in inspect_colorable?'
       14: from /Users/asterite/.rbenv/versions/2.7.0-dev/lib/ruby/2.7.0/irb/color.rb:80:in `inspect_colorable?'
       13: from /Users/asterite/.rbenv/versions/2.7.0-dev/lib/ruby/2.7.0/irb/color.rb:80:in `all?'
       12: from /Users/asterite/.rbenv/versions/2.7.0-dev/lib/ruby/2.7.0/irb/color.rb:80:in `block in inspect_colorable?'
       11: from /Users/asterite/.rbenv/versions/2.7.0-dev/lib/ruby/2.7.0/irb/color.rb:80:in `inspect_colorable?'
       10: from /Users/asterite/.rbenv/versions/2.7.0-dev/lib/ruby/2.7.0/irb/color.rb:80:in `all?'
        9: from /Users/asterite/.rbenv/versions/2.7.0-dev/lib/ruby/2.7.0/irb/color.rb:80:in `block in inspect_colorable?'
        8: from /Users/asterite/.rbenv/versions/2.7.0-dev/lib/ruby/2.7.0/irb/color.rb:80:in `inspect_colorable?'
        7: from /Users/asterite/.rbenv/versions/2.7.0-dev/lib/ruby/2.7.0/irb/color.rb:80:in `all?'
        6: from /Users/asterite/.rbenv/versions/2.7.0-dev/lib/ruby/2.7.0/irb/color.rb:80:in `block in inspect_colorable?'
        5: from /Users/asterite/.rbenv/versions/2.7.0-dev/lib/ruby/2.7.0/irb/color.rb:80:in `inspect_colorable?'
        4: from /Users/asterite/.rbenv/versions/2.7.0-dev/lib/ruby/2.7.0/irb/color.rb:80:in `all?'
        3: from /Users/asterite/.rbenv/versions/2.7.0-dev/lib/ruby/2.7.0/irb/color.rb:80:in `block in inspect_colorable?'
        2: from /Users/asterite/.rbenv/versions/2.7.0-dev/lib/ruby/2.7.0/irb/color.rb:80:in `inspect_colorable?'
        1: from /Users/asterite/.rbenv/versions/2.7.0-dev/lib/ruby/2.7.0/irb/color.rb:80:in `all?'
SystemStackError (stack level too deep)
Maybe IRB bug!

Suggested fix: keep a list of visited arrays and hashes. I will try to submit a patch.

Updated by the-asterite (Ary Borenszweig) about 5 years ago

By the way, I had to create a new account to report this bug. I already tried to reset my password for account asterite@gmail.com but after I reset it if I try to login it always says the password is incorrect. Could you try verifying "reset password" works fine?

Actions #3

Updated by asterite (Ary Borenszweig) about 5 years ago

  • Status changed from Open to Closed

Applied in changeset git|96617ad1d57a13e9a282fb663ea73e4801519389.


IRB colorize: take into account recursive arrays and hashes (#2555)

[Bug #16250]

Updated by k0kubun (Takashi Kokubun) about 5 years ago

Great catch, thanks!

By the way, I had to create a new account to report this bug. I already tried to reset my password for account but after I reset it if I try to login it always says the password is incorrect. Could you try verifying "reset password" works fine?

I'm not familiar with it so much. Please file another ticket somewhere, maybe https://github.com/ruby/bugs.ruby-lang.org/issues?

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0