Environment:
- LDAP Server Type: OpenLDAP
- PHP Version: 8.1
Describe the bug:
We want to store LDAP user objects (extends LdapRecord\Models\Model) in the Laravel session (serialization). However, this causes the problem that LDAP users with names containing Umlaut characters (e.g. "René") are wrongly decoded when the session is loaded (=LDAP user unserialized) again. The UTF-8 string "René" is considered an 'ISO-8859-1' encoded string and converted to UTF-8, which then becomes "René".
It seems that the cause for this a bug in the function decodeValue(string $value) in HasAttributes.php:
https://github.com/DirectoryTree/LdapRecord/blob/master/src/Models/Concerns/HasAttributes.php#L223
I suspect the condition in
if (MbString::isLoaded() && MbString::isUtf8($value)) {
return mb_convert_encoding($value, 'UTF-8', 'ISO-8859-1');
}
Should rather be (notice the !):
if (MbString::isLoaded() && !MbString::isUtf8($value)) {
return mb_convert_encoding($value, 'UTF-8', 'ISO-8859-1');
}
because it makes no sense to convert a string that is already utf-8.
Environment:
Describe the bug:
We want to store LDAP user objects (extends LdapRecord\Models\Model) in the Laravel session (serialization). However, this causes the problem that LDAP users with names containing Umlaut characters (e.g. "René") are wrongly decoded when the session is loaded (=LDAP user unserialized) again. The UTF-8 string "René" is considered an 'ISO-8859-1' encoded string and converted to UTF-8, which then becomes "René".
It seems that the cause for this a bug in the function decodeValue(string $value) in HasAttributes.php:
https://github.com/DirectoryTree/LdapRecord/blob/master/src/Models/Concerns/HasAttributes.php#L223
I suspect the condition in
Should rather be (notice the !):
because it makes no sense to convert a string that is already utf-8.