Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove needless removal of trailing whitespace in check_code_state #678

Merged
merged 1 commit into from
Aug 11, 2023

Conversation

tompng
Copy link
Member

@tompng tompng commented Aug 11, 2023

IRB unnecessarily removes trailing white space before checking should_continue?. It results in failure of executing tricky syntax.

irb(main):001:0" <<"a "
irb(main):002:0" heredoc
irb(main):003:0> a (←whitespace here)
irb(main):004:0> 
irb(main):005:0> 
irb(main):001:0> % ruby (←whitespace here)
irb(main):002:0> 
irb(main):003:0> 
irb(main):004:0> 
irb(main):001:0* %
irb(main):002:0> 
irb(main):003:0> 

Reason why there was gsub and why it's not needed now

The old implementation of should_continue? (process_continue) was assuming tokens[-1] is newline and tokens[-2] is the last non-whitespace token. code.gsub(/\s*\z/, '').concat("\n") was ensuring that assumption.
https://github.com/ruby/irb/pull/611/files#diff-612b926e42ed78aed1a889ac1944f7d22229b3a489cc08f837a7f75eca3d3399L250-L262
The implementation is changed to skip continuous trailing newline, space, and comment-like tokens so we don't need that gsub anymore.

@tompng tompng merged commit 4a6af7d into ruby:master Aug 11, 2023
24 checks passed
matzbot pushed a commit to ruby/ruby that referenced this pull request Aug 11, 2023
@tompng tompng deleted the check_code_state_no_strip branch August 11, 2023 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants