Skip to content

CFStringEncoding: return IANA charset names in lowercase - #119

Open
DTW-Thalion wants to merge 1 commit into
gnustep:masterfrom
DTW-Thalion:fix/cfstringencoding-iana
Open

CFStringEncoding: return IANA charset names in lowercase#119
DTW-Thalion wants to merge 1 commit into
gnustep:masterfrom
DTW-Thalion:fix/cfstringencoding-iana

Conversation

@DTW-Thalion

Copy link
Copy Markdown
Contributor

CFStringConvertEncodingToIANACharSetName returned ICU's canonical converter name (for example "ANSI_X3.4-1968" for US-ASCII and "ISO_8859-1:1987" for ISO Latin 1), but Apple returns the preferred IANA name in lowercase: "utf-8", "us-ascii", "iso-8859-1", "utf-16".

The MIME name is the preferred IANA name and matches Apple's output for the encodings that have one, so it is queried first, falling back to the plain IANA name otherwise. The result is lowercased. The lowercase copy is memoized by ICU's stable name pointer so repeated calls return the same constant string, preserving the previous behaviour of not making multiple copies.

Tests/CFStringEncoding/iana.m covers UTF-8, US-ASCII, ISO Latin 1 and UTF-16. The existing Tests/CFString/encodings.m assertion expected the uppercase "UTF-16" and has been corrected to "utf-16". The expected values match Apple CoreFoundation.

ICU returns IANA names in uppercase, but Apple returns them in lowercase (utf-8,
us-ascii, iso-8859-1). Lowercase the name before returning it.
@DTW-Thalion
DTW-Thalion force-pushed the fix/cfstringencoding-iana branch from 07bde22 to bec457b Compare July 24, 2026 15:29
@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