If I do a reverse interactive search in irb and then enter a control character (arrow keys are the only ones I've seen this with actually). So I start with this session:
$ irb
>> print "hello"
hello
then enter ^r, h
$ irb
>> print "hello"
hello
(reverse-i-search)`he': print "hello"
So far so good. Then I hit the left arrow, and I end up with this:
$ irb
>> print "hello"
hello
>> print "[Dhello"
Subsequent use of the arrows moves the cursor around normally.
This won't solve your problem, but at least I can answer the question you asked (the Why):
The left arrow gets entered into the terminal as three characters, ESC, [, and D. (You can test this by typing
readand pressing the left arrow, which displays^[[D, where^[is how the escape character gets rendered.)Somehow
irbpicks up the ESC character when it shouldn't; so ESC ends the history search, and[Dgets entered literally. Looking at other programs using readline, Bash and Python behave correctly, butledit(yeah, obscure -- sorry ^^) is having this problem as well.Unless someone knows a solution for this, the only workaround I can think of is pressing ESC instead of an arrow key to exit history search. Or hitting enter if you don't need to edit further, of course.