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

Error loading inputrc when file encoding does not match to Encoding.default_external #430

Open
chmaynard opened this issue Feb 17, 2022 · 4 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@chmaynard
Copy link

Description

Using Homebrew, I installed Ruby 3.1 on a Mac running macOS 12.

When I attempt to run irb from the command line using Terminal 2.12, I get this error:

/usr/local/Cellar/ruby/3.1.0/lib/ruby/3.1.0/reline/config.rb:203:in `match': invalid byte sequence in UTF-8 (ArgumentError)
@ima1zumi
Copy link
Member

There seems to be an error at the point where the .inputrc is loaded.
Would you post your .inputrc?

@chmaynard
Copy link
Author

See https://gist.github.com/chmaynard/40e32fc1f302c48cab7f7168ace80c91

@ima1zumi
Copy link
Member

I looked into this issue. But I could not reproduce it. ( macOS 10.15.7 & Terminal 2.10 & Ruby 3.2.0-dev )
In my terminal, it showed up like this.

Apart from that, Reline does not seem to be able to support self-insert.

❯ INPUTRC=.inputrc ASDF_RUBY_VERSION=3.2.0-dev ruby -I /Users/mi/ghq/github.com/ruby/reline/lib -I /Users/mi/ghq/github.com/ruby/irb/lib /Users/mi/ghq/github.com/ruby/irb/exe/irb
irb(main):001:0> 
/Users/mi/ghq/github.com/ruby/reline/lib/reline/line_editor.rb:2024:in `ed_insert': undefined method `chr' for :self_insert:Symbol (NoMethodError)

        key.chr.encode(Encoding::UTF_8)
           ^^^^
        from /Users/mi/ghq/github.com/ruby/reline/lib/reline/line_editor.rb:1492:in `call'
        from /Users/mi/ghq/github.com/ruby/reline/lib/reline/line_editor.rb:1492:in `wrap_method_call'
        from /Users/mi/ghq/github.com/ruby/reline/lib/reline/line_editor.rb:1509:in `process_key'
        from /Users/mi/ghq/github.com/ruby/reline/lib/reline/line_editor.rb:1647:in `input_key'
        from /Users/mi/ghq/github.com/ruby/reline/lib/reline.rb:330:in `block (3 levels) in inner_readline'
        from /Users/mi/ghq/github.com/ruby/reline/lib/reline.rb:328:in `each'
        from /Users/mi/ghq/github.com/ruby/reline/lib/reline.rb:328:in `block (2 levels) in inner_readline'
        from /Users/mi/ghq/github.com/ruby/reline/lib/reline.rb:388:in `block in read_io'
        from /Users/mi/ghq/github.com/ruby/reline/lib/reline.rb:374:in `loop'
        from /Users/mi/ghq/github.com/ruby/reline/lib/reline.rb:374:in `read_io'
        from /Users/mi/ghq/github.com/ruby/reline/lib/reline.rb:326:in `block in inner_readline'
        from /Users/mi/ghq/github.com/ruby/reline/lib/reline.rb:324:in `loop'
        from /Users/mi/ghq/github.com/ruby/reline/lib/reline.rb:324:in `inner_readline'
        from /Users/mi/ghq/github.com/ruby/reline/lib/reline.rb:254:in `readmultiline'
        from /Users/mi/.asdf/installs/ruby/3.2.0-dev/lib/ruby/3.2.0/forwardable.rb:238:in `readmultiline'
        from /Users/mi/.asdf/installs/ruby/3.2.0-dev/lib/ruby/3.2.0/forwardable.rb:238:in `readmultiline'
        from /Users/mi/ghq/github.com/ruby/irb/lib/irb/input-method.rb:417:in `gets'
        from /Users/mi/ghq/github.com/ruby/irb/lib/irb.rb:539:in `block (2 levels) in eval_input'
        from /Users/mi/ghq/github.com/ruby/irb/lib/irb.rb:770:in `signal_status'
        from /Users/mi/ghq/github.com/ruby/irb/lib/irb.rb:538:in `block in eval_input'
        from /Users/mi/ghq/github.com/ruby/irb/lib/irb/ruby-lex.rb:284:in `lex'
        from /Users/mi/ghq/github.com/ruby/irb/lib/irb/ruby-lex.rb:253:in `block (2 levels) in each_top_level_statement'
        from /Users/mi/ghq/github.com/ruby/irb/lib/irb/ruby-lex.rb:250:in `loop'
        from /Users/mi/ghq/github.com/ruby/irb/lib/irb/ruby-lex.rb:250:in `block in each_top_level_statement'
        from /Users/mi/ghq/github.com/ruby/irb/lib/irb/ruby-lex.rb:249:in `catch'
        from /Users/mi/ghq/github.com/ruby/irb/lib/irb/ruby-lex.rb:249:in `each_top_level_statement'
        from /Users/mi/ghq/github.com/ruby/irb/lib/irb.rb:557:in `eval_input'
        from /Users/mi/ghq/github.com/ruby/irb/lib/irb.rb:491:in `block in run'
        from /Users/mi/ghq/github.com/ruby/irb/lib/irb.rb:490:in `catch'
        from /Users/mi/ghq/github.com/ruby/irb/lib/irb.rb:490:in `run'
        from /Users/mi/ghq/github.com/ruby/irb/lib/irb.rb:419:in `start'
        from /Users/mi/ghq/github.com/ruby/irb/exe/irb:11:in `<main>'

@ima1zumi ima1zumi added the enhancement New feature or request label Apr 17, 2024
@tompng tompng added the good first issue Good for newcomers label Jun 17, 2024
@tompng tompng changed the title irb not working because of an invalid byte sequence in UTF-8 Error loading inputrc when file encoding does not match to Encoding.default_external Jun 17, 2024
@tompng
Copy link
Member

tompng commented Jun 17, 2024

To reproduce

Add a multibyte character to .inputrc in some encoding.
Then launtch irb with another encoding.

$ ruby -e "File.write 'dummy_inputrc', '#∞'.encode('sjis')"
$ INPUTRC=dummy_inputrc irb -Eutf-8
reline/lib/reline/config.rb:174:in `match': invalid byte sequence in UTF-8 (ArgumentError)
$ echo '#∞' > dummy_inputrc
$ INPUTRC=dummy_inputrc irb -Esjis
reline/lib/reline/config.rb:174:in `match': invalid byte sequence in Windows-31J (ArgumentError)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Development

No branches or pull requests

3 participants