Repository navigation
Conversation
tompng
reviewed
Oct 12, 2026
| def colorize_code(code, complete: true, ignore_error: false, colorable: colorable?, local_variables: []) | ||
| return code unless colorable | ||
|
|
||
| code = code.gsub("\r\n", "\n") |
Member
There was a problem hiding this comment.
Normalizing CRLF should be done AFTER Prism.parse_lex, not before. The original source code should be passed to the parser.
Replacing \r\n to \n will change the meaning of the code in some case, such as:
eval "%\r\r\na\r"
#=> "\na"
eval "%\r\r\na\r".gsub("\r\n", "\n")
#=> SyntaxError
eval "%\ra\r\r\n"
#=> "a"
eval "%\ra\r\r\n".gsub("\r\n", "\n")
#=> SyntaxErrorReline::Unicode.escape_for_print(code) is the one changing "\r" to "^M".
We can replace Reline::Unicode.escape_for_print(s) to a method call, calling a method defined in IRB::Color that escapes control characters except "\r\n".
Author
|
Moved the normalization after parsing, as you suggested, and added both examples to the tests. I also fixed the failure with the latest Prism, which splits CRLF at the end of a comment across two tokens. The full suite passes locally with both released and development Prism. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refs #1037.
CRLF still appears as
^Minside highlighted comments and multiline strings, including inshow_sourceand the source shown around a binding. Normalize CRLF before parsing colored source so those line endings render normally. Standalone carriage returns remain visible, and uncolored output is unchanged.Changes
Testing
bundle exec rake test TEST=test/irb/test_color.rbbundle exec rake test(410 tests, 0 failures/errors, 2 omissions)bundle exec rubocopbundle exec rake buildVerified on macOS with Ruby 4.0.6. The Windows/Linux and other Ruby version matrices were not run locally.