strip end of line CR from show_source

Open
#1,037 0 comments 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
ruby
Domain
cli

Research direction

Start at the show_source implementation and reproduce the issue with a Ruby source file using CRLF newlines on Windows or WSL. Trace how source lines are read and displayed, then verify that show_source no longer prints a trailing ^M while preserving normal source output.

Written by the indexing model from the issue text.

Description

Description

The ruby parser considers CR to be a whitespace character, but IRB does not seem to do that.
This may result in an extra ^M at the end of a line when viewing the source from IRB.

How to reproduce

Save the following source code in CRLF newline on Windows and execute it on WSL.

def desc
  "this file has CRLF newline"
end
binding.irb
$ ruby /mnt/r/crlf.rb

From: /mnt/r/crlf.rb @ line 4 :

    1: def desc^M
    2:   "this file has CRLF newline"^M
    3: end^M
 => 4: binding.irb^M

irb(main):001> show_source "desc"

From: /mnt/r/crlf.rb:1

def desc^M
  "this file has CRLF newline"^M
end^M

=> nil
irb(main):002>
Dominant language
Ruby
Stars
477
Forks
165
Avg merge
1d 19h
Merged PRs (30d)
5

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ruby/irb

All issues in ruby/irb

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.