[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mb_check_encoding wrong result for 7bit #8128

Closed
divinity76 opened this issue Feb 21, 2022 · 2 comments
Closed

mb_check_encoding wrong result for 7bit #8128

divinity76 opened this issue Feb 21, 2022 · 2 comments

Comments

@divinity76
Copy link
Contributor
divinity76 commented Feb 21, 2022

Description

edit: warning, there's conflicting definitions of 7bit.. according to https://galprop.stanford.edu/bugs/docs/en/html/api/Bugzilla/Util.html it should be

Returns true is the string contains only 7-bit characters (ASCII 32 through 126, ASCII 10 (LineFeed) and ASCII 13 (Carrage Return).

which i guess would be ($o >= 32 && $o <=126) || $o === 10 || $o === 13
, but if that definition is correct, mb_check_encoding's current behavior is still wrong here.. moving on

The following code:

<?php
function is_7bit_clean(string $str):bool{
    for($i=0,$imax=strlen($str);$i<$imax;++$i){
        if(ord($str[$i]) & (1 << 7)){
            return false;
        }
    }
    return true;
}
$str = chr(255);
var_dump(is_7bit_clean($str) === mb_check_encoding($str, '7bit'));

Resulted in this output:

bool(false)

But I expected this output instead:

bool(true)

as of 8.1.2. probably related to GH #7712
3v4l: https://3v4l.org/HZh8A

PHP Version

PHP 8.1.2

Operating System

No response

@alexdowad
Copy link
Contributor

Looks like this was broken in 3e7acf9. Our test suite was not comprehensive enough to catch this change in behavior when mbstring was refactored to combine the identify and conversion filters.

I'm just pushing a commit to fix it.

@alexdowad
Copy link
Contributor

Fixed in #8139.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants
@nikic @alexdowad @divinity76 @cmb69 and others