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

Fix % escape in prompt format #927

Merged
merged 1 commit into from
Apr 18, 2024
Merged

Conversation

tompng
Copy link
Member

@tompng tompng commented Apr 18, 2024

Escaping % in prompt fromatting was not correctly implemented.

# Wrong formatting
IRB::Irb.new.send(:format_prompt, '%% %02i', nil, 1, 1)
=> "%% 01" # should be "% 01"

# Reference
format '%% %02d', 1
=> "% 01"

This pull request fixes it.

irb = IRB::Irb.new(IRB::WorkSpace.new(main), TestInputMethod.new)
assert_equal('%% main %m %main %%m >', irb.send(:format_prompt, '%%%% %m %%m %%%m %%%%m %l', '>', 1, 1))
assert_equal('42,%i, 42,%3i,042,%03i', irb.send(:format_prompt, '%i,%%i,%3i,%%3i,%03i,%%03i', nil, 42, 1))
assert_equal('42,%n, 42,%3n,042,%03n', irb.send(:format_prompt, '%n,%%n,%3n,%%3n,%03n,%%03n', nil, 1, 42))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlike string formatting, /%\d*\z/ /%\d*[^0-9a-zA-Z%]/ /%\d+%/ does not raise error. (Didn't add these to test case)

@st0012 st0012 added the bug Something isn't working label Apr 18, 2024
@tompng tompng merged commit 08eee25 into ruby:master Apr 18, 2024
29 checks passed
@tompng tompng deleted the prompt_format_percent branch April 18, 2024 14:46
matzbot pushed a commit to ruby/ruby that referenced this pull request Apr 18, 2024
artur-intech pushed a commit to artur-intech/ruby that referenced this pull request Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging this pull request may close these issues.

2 participants