Skip to content

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
@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

2 participants