Skip to content

GSUnicode: stop converting at the first unrepresentable character - #123

Open
DTW-Thalion wants to merge 2 commits into
gnustep:masterfrom
DTW-Thalion:fix/gsunicode-loss-refuse
Open

GSUnicode: stop converting at the first unrepresentable character#123
DTW-Thalion wants to merge 2 commits into
gnustep:masterfrom
DTW-Thalion:fix/gsunicode-loss-refuse

Conversation

@DTW-Thalion

Copy link
Copy Markdown
Contributor

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.

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
DTW-Thalion force-pushed the fix/gsunicode-loss-refuse branch from 91f6988 to b1e1b03 Compare July 24, 2026 15:22
@DTW-Thalion DTW-Thalion reopened this Jul 24, 2026
@DTW-Thalion DTW-Thalion reopened this Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant