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

Refactor utf-8 strings and invalid strings in test code #800

Merged
merged 5 commits into from
Jan 5, 2025

Conversation

tompng
Copy link
Member

@tompng tompng commented Jan 1, 2025

This pull request resolves the problem mentioned in the source code comment in input_keys.

def input_keys(input, convert = true)
   # Reline does not support convert-meta, but test data includes \M-char. It should be converted to ESC+char.
   # Note that mixing unicode chars and \M-char is not recommended. "\M-C\M-\C-A" is a single unicode character.
   ...
end

"\M-[char]" should be removed from test code because it is an invalid byte sequence string.
Reline only accepts "\e[char]" which is sent by Meta-[char] key input in modern terminal emulators.

After invalid byte sequence are removed, we don't need convert option in method input_keys because valid strings does not need to skip convert.

Other changes

def convert_str(input) can be simpler.
If the input needs unicode_normalize before conversion, then the prerequisites of the test (input unicode-unnormalized text) are broken. We just need to omit the test if the test encoding is not utf-8.

private def convert_str(input, options = {}, normalized = nil)
return nil if input.nil?
input = input.chars.map { |c|
if Reline::Unicode::EscapedChars.include?(c.ord)
Copy link
Member

Choose a reason for hiding this comment

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

Reline::Unicode::EscapedChars is no longer use. Could you remove it?

EscapedChars = EscapedPairs.keys.map(&:chr)

~/ghq/github.com/ruby/reline test_rm_invalid_encoding
❯ git grep EscapedChars
lib/reline/unicode.rb:  EscapedChars = EscapedPairs.keys.map(&:chr)

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed 👍
I also added two more commits that removes \M-[char] from test_within_pipe.rb and from test_rendering.rb

test/reline/helper.rb Show resolved Hide resolved
tompng added 5 commits January 5, 2025 15:40
yamatanooroti handles invalid byte sequence input "\M-[char]" and converts it to "\e[char]"
We don't need to use these invalid byte sequence and rely on the hack implemented in yamatanooroti
@tompng tompng force-pushed the test_rm_invalid_encoding branch from 38300af to c7b8dac Compare January 5, 2025 06:51
Copy link
Member

@ima1zumi ima1zumi left a comment

Choose a reason for hiding this comment

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

LGTM!

@ima1zumi ima1zumi merged commit f09e7b1 into ruby:master Jan 5, 2025
45 checks passed
matzbot pushed a commit to ruby/ruby that referenced this pull request Jan 5, 2025
code
(ruby/reline#800)

* Remove invalid encoding string "\M-[char]" from test code, remove unused code/arg/options

* Omit unicode unnoralized input test in non-utf8 testcase

* Remove helper method and constant no longer used in testcode

* Change key binding test to use realistic bytes instead of invalid byte sequence

* Remove invalid byte sequence input from rendering test

yamatanooroti handles invalid byte sequence input "\M-[char]" and converts it to "\e[char]"
We don't need to use these invalid byte sequence and rely on the hack implemented in yamatanooroti

ruby/reline@f09e7b154c
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