Repository navigation
Conversation
StringIO#getc split a truncated multi-byte character at the end of
the string into single bytes, while IO#getc returns the remaining
bytes of the incomplete character together:
io = File.open(path_with_bytes_a\xE3\x81) # UTF-8
io.getc # => "a"
io.getc # => "\xE3\x81"
sio = StringIO.new("a\xE3\x81".dup.force_encoding(Encoding::UTF_8))
sio.getc # => "a"
sio.getc # => "\xE3" (then "\x81")
Use rb_enc_precise_mbclen in strio_getc: when the character is
incomplete because the string ends (MBCLEN_NEEDMORE), consume all
remaining bytes; when it is invalid, keep returning a single byte.
This branch has not been deployed
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.
StringIO#getcsplits a truncated multi-byte character at the end of the string into single bytes, whileIO#getcreturns the remaining bytes of the incomplete character together:This is the
getccounterpart of the truncated-character cases already handled forgetswith a limit (test_gets_limit_around_truncated_char).The fix uses
rb_enc_precise_mbcleninstrio_getc: when the character is incomplete because the string ends (MBCLEN_NEEDMORE), all remaining bytes are consumed; when the byte sequence is invalid, the current single-byte behavior is kept.readcharis fixed throughgetc. Valid characters and invalid bytes are unchanged.Tests:
test_getc_at_truncated_charandtest_readchar_at_truncated_char. Both fail on unpatched master and pass with this change; the rest of the test suite is unchanged (verified against a baseline build).