Repository navigation
fix: remap GB18030-2022 PUA codepoints to equivalent Unicode - #735
Conversation
Reviewer's GuideImplementationDefine the GB18030-2022 PUA-to-Unicode mappings and apply them to decoded GB18030 data after iconv conversion.
Detect the destination encoding and apply GB18030 replacement handling regardless of whether patched iconv is enabled.
TestsUpdate the expected remapped output and add standard-iconv coverage for vertical punctuation and CJK Extension B mappings.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/encodes/detectcode.cpp" line_range="980" />
<code_context>
+ // 无字体覆盖导致乱码,重映射为 2005 标准 Unicode 码位
+ if (GB18030 == fromMib && UTF_8 == toMib) {
+ for (auto itr = gs_PUA2022ToUnicode2005.begin(); itr != gs_PUA2022ToUnicode2005.end(); ++itr) {
+ convertedData.replace(itr.key(), itr.value());
+ }
+ }
</code_context>
<issue_to_address>
**Valid private-use text changes**
When GB18030 decoding produces a mapped PUA scalar from intentional private-use text or a valid legacy mapping, `convertedData.replace()` changes every matching PUA scalar, including ones that should be preserved; `readFile` returns different text and saving can persist the corruption.
Apply the remapping only to the GB18030 byte sequences whose interpretation changed, rather than to every matching decoded PUA scalar.
</issue_to_address>
### Comment 2
<location path="src/encodes/detectcode.cpp" line_range="858" />
<code_context>
- if (GB18030 == fromMib && UTF_8 == toMib) {
- qCDebug(appLog) << "Converting from GB18030 to UTF-8, applying 2005 error replacements";
- for (auto itr = gs_ReplaceFromGB18030_2005Error.begin(); itr != gs_ReplaceFromGB18030_2005Error.end(); ++itr) {
- inputStr.replace(itr.key(), itr.value());
- }
- } else if (UTF_8 == fromMib && GB18030 == toMib) {
</code_context>
<issue_to_address>
**Neighboring characters are corrupted**
When a valid two-byte GB18030 character ending in `0xFE` is followed by ASCII `Q` (`0x51`), `inputStr.replace()` matches `FE51` across the character boundary and inserts the sentinel; the error handler then emits incorrect text for the neighboring characters.
Apply replacements only to complete GB18030 character sequences, without matching across character boundaries.
</issue_to_address>
### Comment 3
<location path="src/encodes/detectcode.cpp" line_range="861-864" />
<code_context>
- inputStr.replace(itr.key(), itr.value());
- }
- } else if (UTF_8 == fromMib && GB18030 == toMib) {
- qCDebug(appLog) << "Converting from UTF-8 to GB18030, applying 2020 error replacements";
- for (auto itr = gs_ReplaceToGB18030_2020Error.begin(); itr != gs_ReplaceToGB18030_2020Error.end(); ++itr) {
- inputStr.replace(itr.key(), itr.value());
- }
+ // 替换需手动修改 UTF-8 和 GB18030 编码转换的部分
+ if (GB18030 == fromMib && UTF_8 == toMib) {
</code_context>
<issue_to_address>
**GB18030 saves corrupt Unicode**
When standard iconv is used to save UTF-8 text containing one of the six mapped Unicode characters as GB18030, `ChangeFileEncodingFormat` replaces characters such as U+20087 with the `FFFF11` sentinel, but `checkUTF8ToGB18030Error` does not recognize that sentinel; its EILSEQ path emits `?` while consuming the sentinel bytes, so saving these characters as GB18030 corrupts them.
Handle the sentinel explicitly in the EILSEQ path, or avoid substituting it on iconv paths that cannot decode it.
</issue_to_address>| // 无字体覆盖导致乱码,重映射为 2005 标准 Unicode 码位 | ||
| if (GB18030 == fromMib && UTF_8 == toMib) { | ||
| for (auto itr = gs_PUA2022ToUnicode2005.begin(); itr != gs_PUA2022ToUnicode2005.end(); ++itr) { | ||
| convertedData.replace(itr.key(), itr.value()); |
There was a problem hiding this comment.
🟡 Medium · Valid private-use text changes
When GB18030 decoding produces a mapped PUA scalar from intentional private-use text or a valid legacy mapping, convertedData.replace() changes every matching PUA scalar, including ones that should be preserved; readFile returns different text and saving can persist the corruption.
Apply the remapping only to the GB18030 byte sequences whose interpretation changed, rather than to every matching decoded PUA scalar.
Prompt for AI agents
In `src/encodes/detectcode.cpp` at line 980:
**Valid private-use text changes**
When GB18030 decoding produces a mapped PUA scalar from intentional private-use text or a valid legacy mapping, `convertedData.replace()` changes every matching PUA scalar, including ones that should be preserved; `readFile` returns different text and saving can persist the corruption.
Apply the remapping only to the GB18030 byte sequences whose interpretation changed, rather than to every matching decoded PUA scalar.| if (GB18030 == fromMib && UTF_8 == toMib) { | ||
| qCDebug(appLog) << "Converting from GB18030 to UTF-8, applying 2005 error replacements"; | ||
| for (auto itr = gs_ReplaceFromGB18030_2005Error.begin(); itr != gs_ReplaceFromGB18030_2005Error.end(); ++itr) { | ||
| inputStr.replace(itr.key(), itr.value()); |
There was a problem hiding this comment.
🟡 Medium · Neighboring characters are corrupted
When a valid two-byte GB18030 character ending in 0xFE is followed by ASCII Q (0x51), inputStr.replace() matches FE51 across the character boundary and inserts the sentinel; the error handler then emits incorrect text for the neighboring characters.
Apply replacements only to complete GB18030 character sequences, without matching across character boundaries.
Prompt for AI agents
In `src/encodes/detectcode.cpp` at line 858:
**Neighboring characters are corrupted**
When a valid two-byte GB18030 character ending in `0xFE` is followed by ASCII `Q` (`0x51`), `inputStr.replace()` matches `FE51` across the character boundary and inserts the sentinel; the error handler then emits incorrect text for the neighboring characters.
Apply replacements only to complete GB18030 character sequences, without matching across character boundaries.| qCDebug(appLog) << "Converting from UTF-8 to GB18030, applying 2020 error replacements"; | ||
| for (auto itr = gs_ReplaceToGB18030_2020Error.begin(); itr != gs_ReplaceToGB18030_2020Error.end(); ++itr) { | ||
| inputStr.replace(itr.key(), itr.value()); | ||
| } |
There was a problem hiding this comment.
🟡 Medium · GB18030 saves corrupt Unicode
When standard iconv is used to save UTF-8 text containing one of the six mapped Unicode characters as GB18030, ChangeFileEncodingFormat replaces characters such as U+20087 with the FFFF11 sentinel, but checkUTF8ToGB18030Error does not recognize that sentinel; its EILSEQ path emits ? while consuming the sentinel bytes, so saving these characters as GB18030 corrupts them.
Handle the sentinel explicitly in the EILSEQ path, or avoid substituting it on iconv paths that cannot decode it.
Prompt for AI agents
In `src/encodes/detectcode.cpp` at lines 861-864:
**GB18030 saves corrupt Unicode**
When standard iconv is used to save UTF-8 text containing one of the six mapped Unicode characters as GB18030, `ChangeFileEncodingFormat` replaces characters such as U+20087 with the `FFFF11` sentinel, but `checkUTF8ToGB18030Error` does not recognize that sentinel; its EILSEQ path emits `?` while consuming the sentinel bytes, so saving these characters as GB18030 corrupts them.
Handle the sentinel explicitly in the EILSEQ path, or avoid substituting it on iconv paths that cannot decode it.Root cause: on GB18030-2022 systems glibc iconv converts FE51 and four-byte sequences 8431xxxx/8235xxxx to PUA codepoints (U+E816, U+E78D, U+E81E etc.) which have no standard font glyph coverage, causing garbled display in the editor. Fix: extend the post-iconv PUA remapping table to 24 entries, covering vertical forms (E78D-E796 -> U+FE10-FE19), CJK Ext B (E81E series -> U+9FB4-9FBB, E816 series -> U+20087 etc.), and move the GB18030 replacement logic outside the enablePatchedIconv gate so it also runs with standard iconv. 在 GB18030-2022 标准系统上,glibc iconv 将 FE51 及四字节序列 8431xxxx/8235xxxx 转换为无标准字形覆盖的 PUA 码位(U+E816、 U+E78D、U+E81E 等),导致编辑器显示乱码。 扩展 iconv 转换后的 PUA 重映射表至 24 项:竖排形式 (E78D-E796 -> U+FE10-FE19)、CJK 扩展 B(E81E 系列 -> U+9FB4-9FBB、E816 系列 -> U+20087 等),并将 GB18030 替换 逻辑移出 enablePatchedIconv 门控,使标准 iconv 下同样生效。 Log: 修复 GB18030-2022 特殊字符显示乱码问题 PMS: BUG-382849
a7260b7 to
ba278db
Compare
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: add-uos, lzwind The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 语法正确,逻辑清晰 ✅ 通过 潜在问题: 建议: [] 2. 代码质量 ✅评价: 代码结构清晰,注释完整 ✅ 通过 潜在问题: 建议: [] 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: [] 4. 代码安全 🔒评价: 存在0个安全漏洞 ✅ 通过
安全漏洞详情: 建议: [] 💡 改进建议代码示例本次提交无需修复,代码质量良好。建议保持现有注释风格,后续如需扩展映射表可考虑按 Unicode 区段 分组并添加区段头注释。本报告由 AI 代码审查工具自动生成 |
|
/merge |
fix: 修复 GB18030-2022 特殊字符在编辑器中显示乱码
PMS: BUG-382849(【V25 2500U2】【文本编辑器】【6.5.65】打开GB18030编码格式的文件显示乱码)
1. 根因
GB18030-2022 标准系统上(glibc ≥ 2.38),iconv 将以下 GB18030 码位转换为 PUA 私用区码位,而 PUA 无标准字形覆盖,导致编辑器显示乱码(豆腐块或字体 fallback 出怪字):
等价关系的依据:
localedata/charmaps/GB18030(commit e1d3312015, BZ #30243)官方注释明确标注:These PUA mappings use equivalents <U20087>, <U20089> and <U200CC>、This 1 PUA mapping uses the equivalent <U9FB4>2. 方案
在 iconv 转换后应用 PUA → 正式 Unicode 重映射表(共 24 项):
E796 → U+FE10FE19enablePatchedIconv门控,使标准 iconv 环境下同样生效3. 验证
test_common2149/149 通过(含新增 E78D→FE10、E81E→9FB4 端到端测试)FE19 / U+9FB49FBB / U+20087 系在本机有 56~60 个字体覆盖4. 影响
Log: 修复 GB18030-2022 特殊字符显示乱码的问题
Summary by Sourcery
Remap GB18030-2022 iconv private-use output to equivalent Unicode code points so affected characters render correctly in the editor.
Bug Fixes:
Enhancements:
Tests: