gh-155016: Fix encoding to Windows code pages which require dwFlags=0 - #155018
Open
serhiy-storchaka wants to merge 1 commit into
Open
gh-155016: Fix encoding to Windows code pages which require dwFlags=0#155018serhiy-storchaka wants to merge 1 commit into
serhiy-storchaka wants to merge 1 commit into
Conversation
…lags=0 WideCharToMultiByte() only converts to some code pages (ISO-2022, HZ-GB2312, GB18030, ISCII and UTF-7) with dwFlags set to 0 and lpUsedDefaultChar set to NULL, and rejects any other call with ERROR_INVALID_PARAMETER. Encode to them with these arguments, and detect replaced characters by decoding the result back, since lpUsedDefaultChar is no longer available for this. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Encode with
dwFlags = 0andlpUsedDefaultChar = NULLto the code pages which only support this: 42 (Symbol), 50220, 50221, 50222, 50225, 50227, 50229 (ISO-2022), 52936 (HZ-GB2312), 54936 (GB18030) and 57002-57011 (ISCII). UTF-7 was already special cased, now it shares the same code.Since
lpUsedDefaultCharis no longer available for these code pages, replaced characters are detected by decoding the encoded string back and comparing it with the original string. This also detects best fit characters, whichdwFlags = 0re-enables.The per-character buffer in
encode_code_page_errors()is enlarged from 4 to 16 bytes, because a single character encoded together with escape sequences is longer than that (up to 9 bytes in cp50220). Only code pages encoded withdwFlags = 0use more than 4 bytes per character.