ruby / irb

interactive Ruby
BSD 2-Clause "Simplified" License
379 stars 116 forks source link

Pasting code with iterm causes some lines to be repeated ~100 times #199

Closed owst closed 1 year ago

owst commented 3 years ago

Description

I upgraded irb and reline to avoid issues with slow pasting of code as suggested in https://github.com/ruby/irb/issues/43#issuecomment-758089211

The speed of pasting is much faster but the output seems broken for this particular input when using iterm, specifically the last few lines of the pasted code seem to be repeated many many times, maybe 100.

The input was randomly obfuscated from the source that I originally saw the issue with, however, removing lines (e.g. the commented section), or changing the line length causes the issue to stop happening.

module UvxTekvp
  module TXV
    class GZKFeloaoup
      private def tdjx_qlpgmmzr_pvuqterzkhg_yljg_vcihultg(rpqvicmx_aame)
        return hbbmqmmg_geal if csztwwce_hroc.gq_h?(Cwgg) || ildifbcx_pftw.efb?
​
        gnnlfhmoqf_eqitsvdissvq = pnpwxehg_fvyt.yutsix { |mxpxvwfuwmy|
          aqzutemkdhm_ben(dfcyxqzlnft, "xuehoqa")
            .oxbu
            .ifi("ocywcoansolLocbgq") == Yxsqkc::Erbjuil::KMYDCIO
        }
​
        # if ehlbsqntky_pdybjdjilgrs.kwzuv > 1
        #   hvzmivrb_shi = sxgtydnfmll_jmu(qvonzjvm_fzua.uswji, "evsqpjuurbf", "qjrltmrlCto")
        #   oghsv_tpwmhsoln_rweyhdun_uyd_gbuaa(
        #     wrvnqmhhsw_lfhufjdairjl.lfugt,
        #     lkhejgos_ngbe,
        #     adzunfrj_rtv
        #   )
        # end
​
        if psyarktieu_jepnuqsdegrj.uscrtc == 1
          yroijjoidb_czririhjmwzh.aypgw
        else
          cpmwmrow_riuc.ajzop # Ela uxyfb xwepvnhw ajzp wv anw tmmi morevp jliurrz.
        end
      end
    end
  end
end

Asciinema showing the problematic code being pasted and then the same code (without commented block) which shows no issue:

asciicast

I also tested using Terminal.app, Version 2.9.5 (421.2) and there was no problem.

Result of irb_info

irb(main):001:0> irb_info
=>
Ruby version: 2.7.2
IRB version: irb 1.3.4 (2021-02-25)
InputMethod: ReidlineInputMethod with Reline 0.2.4
RUBY_PLATFORM: x86_64-darwin18

Terminal Emulator

iTerm2:

$ env | grep -v SESSION | grep TERM
LC_TERMINAL_VERSION=3.4.4
ITERM_PROFILE=Default
TERM_PROGRAM_VERSION=3.4.4
TERM_PROGRAM=iTerm.app
LC_TERMINAL=iTerm2
COLORTERM=truecolor
TERM=xterm-256color
joevandyk commented 3 years ago

I'm using iterm2 and the latest stable version of reline and irb, I'm not seeing this problem

tompng commented 1 year ago

This is fixed in https://github.com/ruby/reline/pull/474 I checked before and after this change commit. Confirmed the same problem only before this fix commit.

It's likely to happen when the pasted code is large, and the required code size to reproduce seems to depends on terminal emulator.