ConnorAtherton / rb-readline

Pure-Ruby Readline Implementation
BSD 3-Clause "New" or "Revised" License
245 stars 55 forks source link

Cryptic error from rbreadline caused by unquoted key-combo in .inputrc when running irb. #17

Closed codeferret1 closed 13 years ago

codeferret1 commented 13 years ago

In my .inputrc the following line:

C-u: possible-completions

causes: C:/Ruby192/lib/ruby/site_ruby/1.9.1/rbreadline.rb:2398:in instance_eval': uninitialized constant Module::C (NameError) from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rbreadline.rb:2398:ininstance_eval'

For the unsurprising reason that it is trying to evaluate the C as-is, not as a string.

Changing the line to: "C-u": possible-completions

Fixes the error.

I was rather slow at finding the cause of this (http://groups.google.com/group/rubyinstaller/browse_thread/thread/fb14c5a950e335e4#).
It may be helpful to have a more to-the-point error message (or just handle unquoted key-combos).

-------------- Environment Ruby version: 1.8.7 Installed on windows via 1.8.7p302 RubyInstaller from rubyinstaller.org Windows 7

Steps to repro:

  1. Install ruby via ruby installer.
  2. Create .inputrc like this in home directory:

    BEGIN FILE

    C-u: possible-completions

    END FILE

  3. run irb
  4. Confirm the cryptic error
  5. Change .inputrc file to "C-u": possible-completions
  6. run irb
  7. Confirm there is no error :)
luislavena commented 13 years ago

Seems that the root of the issue is key = instance_eval(key)

Wonder why key is been install evaled.

Asking Park (the author) right now.

codeferret1 commented 13 years ago

Yes, now that you mention it this does allow me to run arbitrary ruby code from my .inputrc:

BEGIN FILE

"C-u": possible-completions
puts "hi"
system("rm my_important_file.txt")
# END FILE

$ touch my_imporant_file.txt

$ irb

"hi" is printed

$ ctrl-D

$ ls | grep important

$

... Is that working as intended?

luislavena commented 13 years ago

No, inputrc should not be processed like active code

luislavena commented 13 years ago

Do not eval inputrc defitions. Closed by 28d987edc2fe8cc2684fa3e1bf612374b090d079