mb_check_encoding is detecting SJIS as Windows-1252 in PHP 8.1
Open
@alexdowad is already working on this.
Since Mar 22, 2024.
Bug
Extension: mbstring
Status: Needs Triage
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
Description
Works as expected in 7.4
The following code:
<?php
$string = mb_convert_encoding('パーティーへ行かないか', 'SJIS', 'UTF-8');
var_dump(mb_check_encoding($string, 'SJIS')); // should be valid
var_dump(mb_check_encoding($string, 'Windows-1252')); // should be invalid
var_dump(mb_detect_encoding($string, 'SJIS', true)); // should be valid
var_dump(mb_detect_encoding($string, 'Windows-1252', true)); // should be invalid
var_dump(mb_convert_encoding($string, 'UTF-8', 'SJIS')); // should be correct
var_dump(mb_convert_encoding($string, 'UTF-8', 'Windows-1252')); // should be wrong
Resulted in this output:
bool(true)
bool(true)
string(4) "SJIS"
string(12) "Windows-1252"
string(33) "パーティーへ行かないか"
string(43) "ƒp[ƒeƒB[‚Ös‚©‚È‚¢‚©"
But I expected this output instead:
bool(true)
bool(false)
string(4) "SJIS"
bool(false)
string(33) "パーティーへ行かないか"
string(46) "ƒp�[ƒeƒB�[‚Ö�s‚©‚È‚¢‚©"
PHP Version
PHP 8.1.27
Operating System
CentOS 7
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.