Add validation for Encoding.default_external#829
Merged
Conversation
tompng
reviewed
Jun 14, 2025
| unless line.valid_encoding? | ||
| mes = "Warning invalid byte sequence found at line #{no + 1} in inputrc file#{file ? " (#{file})" : ""}. can't be converted to the locale #{Encoding.default_external}." | ||
| warn mes | ||
| next |
Member
There was a problem hiding this comment.
inputrc file has a structure.
$if Rubyx
"\C-a": "Ruby"
$else [invalid string on this line]
"\C-b": "NotRuby"
$endifIgnoring only the invalid line can cause unintentional result.
I think raising InvalidInputrc is better.
# Example on L208, when `$if` and `$endif does not match
unless if_stack.empty?
raise InvalidInputrc, "#{file}:#{if_stack.last[0]}: unclosed if"
enddad84a4 to
debc103
Compare
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
This PR introduces a check to detect and warn about encoding inconsistencies between the
inputrcfile (specified via theINPUTRCenvironment variable) andEncoding::default_external. The goal is to prevent or help diagnoseArgumentError: invalid byte sequenceerrors that can occur, for example, during regular expression processing, if theinputrcfile contains byte sequences incompatible withEncoding::default_external.Background
Currently, when an
inputrcfile specified by theINPUTRCenvironment variable is loaded, its content is processed. An attempt is made to handle encoding, for instance, usingx.encode(Reline.encoding_system_needs).However, this encoding step does not always guarantee that all byte sequences become valid for
Encoding::default_external. If the sourceinputrcfile has an encoding that is not fully convertible toEncoding::default_external, or if it contains characters that are inherently invalid inEncoding::default_external, problematic byte sequences can persist.When these unprocessed or incompatibly encoded byte sequences are subsequently passed to operations like regular expression matching, an
ArgumentError: invalid byte sequence in <Encoding_Name>(where<Encoding_Name>is typicallyEncoding::default_external) can be raised if they are not valid according toEncoding::default_external.(#430 )Proposed Solution
This PR addresses the issue by implementing the following:
x.encode(Reline.encoding_system_needs)) on the content from theinputrcfile.inputrc) is compatible withEncoding::default_external.Encoding::default_external, a warning message is issued to the user. This warning will inform the user about the detected encoding mismatch for theinputrcfile.This allows users to be proactively notified if their
inputrcfile's encoding might cause issues with the currentEncoding::default_externalsetting.Impact
invalid byte sequenceerrors: By warning about incompatible characters early, it can help users identify and fix theirinputrcfile before it causes runtime errors, or at least make debugging easier.inputrcconfigurations.How to Test
use https://gist.github.com/chmaynard/40e32fc1f302c48cab7f7168ace80c91