Make Int#chr
reject surrogate halves
#10451
Merged
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.
Resolves #10440.
This completes my own review of the standard library's calls to
Int#chr
and#unsafe_chr
. The result is:Int#chr
raises ifself
is within 0xD800 - 0xDFFF.#unsafe_chr
in the standard library are guaranteed to be safe, either by surrounding code (offending calls will be fixed in Disallow surrogate halves in escape sequences of string and character literals #10443, MakeIO#read_char
's default behaviour UTF-8-strict #10446, Fix JSON::Lexer's UTF-16 escape sequence parsing #10450), or because they come from aBytes
orPointer(UInt8)
(the more common case). Note that aString
can still hold invalid codepoints but safe access from outside would produce the replacement character.Char
's own methods will now assumeself
always represents a valid UTF-8 codepoint, so#each_byte
no longer raises on invalid ones.