Project

General

Profile

Bug #1843

Symbol#inspect raises exception

Added by candlerb (Brian Candler) about 11 years ago. Updated over 9 years ago.

Status:
Closed
Priority:
Normal
Target version:
-
ruby -v:
ruby 1.9.2dev (2009-07-18 trunk 24186) [i686-linux]
Backport:
[ruby-core:24621]

Description

=begin
If you can create an object, I think you should always be able to inspect it.

However Symbol#inspect raises an exception if it was made from a string with an invalid encoding.

"hello\xff".to_sym.inspect
ArgumentError: invalid byte sequence in UTF-8
from (irb):26:in inspect'
from (irb):26
from /usr/local/bin/irb19:12:in
'

Note that the to_sym is quite happy; it's the inspect which fails.

"hello\xff".to_sym; nil
=> nil

This means you cannot handle such objects in irb.

s = :"hello\xff"
ArgumentError: invalid byte sequence in UTF-8
from /usr/local/lib/ruby/1.9.1/irb/inspector.rb:84:in inspect'
from /usr/local/lib/ruby/1.9.1/irb/inspector.rb:84:in
block in module:IRB'
from /usr/local/lib/ruby/1.9.1/irb/inspector.rb:30:in call'
from /usr/local/lib/ruby/1.9.1/irb/inspector.rb:30:in
inspect_value'
from /usr/local/lib/ruby/1.9.1/irb/context.rb:259:in inspect_last_value'
from /usr/local/lib/ruby/1.9.1/irb.rb:301:in
output_value'
from /usr/local/lib/ruby/1.9.1/irb.rb:150:in block (2 levels) in eval_input'
from /usr/local/lib/ruby/1.9.1/irb.rb:263:in
signal_status'
from /usr/local/lib/ruby/1.9.1/irb.rb:146:in block in eval_input'
from /usr/local/lib/ruby/1.9.1/irb/ruby-lex.rb:244:in
block (2 levels) in each_top_level_statement'
from /usr/local/lib/ruby/1.9.1/irb/ruby-lex.rb:230:in loop'
from /usr/local/lib/ruby/1.9.1/irb/ruby-lex.rb:230:in
block in each_top_level_statement'
from /usr/local/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in catch'
from /usr/local/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in
each_top_level_statement'
from /usr/local/lib/ruby/1.9.1/irb.rb:145:in eval_input'
from /usr/local/lib/ruby/1.9.1/irb.rb:69:in
block in start'
from /usr/local/lib/ruby/1.9.1/irb.rb:68:in catch'
from /usr/local/lib/ruby/1.9.1/irb.rb:68:in
start'
from /usr/local/bin/irb19:12:in `'Maybe IRB bug!!

=end

Also available in: Atom PDF