GSUnicode: stop converting at the first unrepresentable character - #123
Open
DTW-Thalion wants to merge 2 commits into
Open
GSUnicode: stop converting at the first unrepresentable character#123DTW-Thalion wants to merge 2 commits into
DTW-Thalion wants to merge 2 commits into
Conversation
When encoding to ASCII or ISO Latin 1 with no loss byte, GSUnicodeToEncoding substituted a NUL byte for characters outside the target range and kept going. Stop at the first unrepresentable character instead so the caller sees how many characters were actually converted.
DTW-Thalion
force-pushed
the
fix/gsunicode-loss-refuse
branch
from
July 24, 2026 15:22
91f6988 to
b1e1b03
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.
When CFStringGetBytes encodes to ASCII or ISO Latin 1 and no loss byte is supplied, GSUnicodeToEncoding substituted a NUL byte (the zero loss byte) for every character outside the target range and continued, so an unconvertible string reported a full conversion made of NUL bytes.
Stop at the first unrepresentable character when no loss byte is given, leaving the source position there. The representable prefix is still converted and the returned count reflects only the characters that fit, matching Apple.
Tests/CFString/getbytes_lossless.m covers U+00E9 to ASCII, U+0100 to ISO Latin 1 and a mixed string that converts its ASCII prefix and stops. Verified against Apple CoreFoundation.