mb_strtoupper converts non-alphabetic characters in Shift_JIS (CP932)
还没有人认领这个 Issue。
- 主要语言
- C
- 星标
- 40.4k
- 派生
- 8.2k
- 平均合并
- 2 天 13 小时
- 30 天内合并 PR
- 96
描述
Description
mb_strtoupper converts non-alphabetic characters in Shift_JIS (CP932)
var_dump(
"\x81\xE0" === mb_strtoupper("\x87\x90", 'cp932')
);
\x81\xE0 and \x87\x90 mean ≒ (U+2252: Approximately Equal to or the Image Of).
var_dump(
"\u{2252}" === mb_convert_encoding("\x81\xE0", 'utf-8', 'cp932'),
"\u{2252}" === mb_convert_encoding("\x87\x90", 'utf-8', 'cp932')
);
\x87\x90 is the one of NEC special characters and was registered in duplicate for historical reasons.
The unintended conversion is caused by a round-trip conversion between Unicode and Shift_JIS.
var_dump(
"\x81\xE0" === roundtrip("\x87\x90", 'cp932'),
"\x81\xE0" === roundtrip("\x81\xE0", 'cp932')
);
function roundtrip($char, $enc) {
return mb_convert_encoding(mb_convert_encoding($char, 'utf-8', $enc), $enc, 'utf-8');
}
As far as I know, 398 characters in Shift_JIS are affected by round-trip conversion. The test code is here.
The same problem applies to mb_scrub, mb_strtolower, mb_convert_case.
var_dump(
"\x81\xE0" === mb_scrub("\x87\x90", 'cp932'),
"\x81\xE0" === mb_strtolower("\x87\x90", 'cp932'),
"\x81\xE0" === mb_strtoupper("\x87\x90", 'cp932'),
"\x81\xE0" === mb_convert_case("\x87\x90", MB_CASE_TITLE, 'cp932')
);
PHP Version
PHP 8.2.10
Operating System
Debian 11.7 (Google ChromeOS 117.0)
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
复现提供的 CP932 示例,并以 mb_scrub、mb_strtolower、mb_strtoupper 和 mb_convert_case 入口作为起始范围。完成的标准是,重复的 NEC 字符序列仍与其规范 CP932 序列保持不同,而不是被往返转换更改,并且受影响的行为已通过测试覆盖。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- php
- 领域
- internationalization
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 38/100