Repository navigation
Conversation
Valid 4-byte characters from U+40000 upward were split apart, and an overlong, surrogate, or truncated sequence was kept or raised. A bad lead is now cleaned alone so the following character stays intact.
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.
Problem
Mail::Multibyte::Unicode.tidy_bytestreated every byte above0xF0as unused. A valid character such as U+40000 (F1 80 80 80) or U+10FFFF (F4 8F BF BF) was split into a Latin-1 lead plus CP1252 bytes.The same walk accepted a sequence whenever the following bytes merely looked like continuations. An overlong encoding and a truncated euro sign then raised
ArgumentErrorfromunpack("U*"). A surrogate (ED A0 80) was left in the result, so the string was still invalid UTF-8.Fix
A sequence is kept only when it is complete and the codepoint is in range: leads are
C2..F4, with the usual second-byte limits forE0,ED,F0, andF4. Anything else is cleaned one byte at a time, which leaves a following character alone.U+40000 and U+10FFFF now round-trip. U+00E9, the euro sign, an emoji, and the CP1252 quote
0x93still do too, includingtidy_bytes(bytes, true). Overlong, surrogate, out-of-range, and truncated input returns valid UTF-8 instead of raising, and a surrogate no longer hides theéafter it.spec/mail/multibyte_spec.rbandspec/mail/utilities_spec.rb: 106 examples, 0 failures.Fixes #1680