treat iconv issues

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
Arthur Schiwon 2018-03-05 14:03:08 +01:00
parent 4f8c724318
commit 47a10bd25a
No known key found for this signature in database
GPG Key ID: 7424F1874854DF23
2 changed files with 13 additions and 5 deletions

View File

@ -1307,13 +1307,18 @@ class Access extends LDAPUtility implements IUserTools {
* @throws \InvalidArgumentException
*/
public function sanitizeUsername($name) {
$name = trim($name);
if($this->connection->ldapIgnoreNamingRules) {
return trim($name);
return $name;
}
// Transliteration
// latin characters to ASCII
$name = iconv('UTF-8', 'ASCII//TRANSLIT', trim($name));
// Transliteration to ASCII
$transliterated = @iconv('UTF-8', 'ASCII//TRANSLIT', $name);
if($transliterated !== false) {
// depending on system config iconv can work or not
$name = $transliterated;
}
// Replacements
$name = str_replace(' ', '_', $name);

View File

@ -633,13 +633,16 @@ class AccessTest extends TestCase {
}
public function intUsernameProvider() {
// system dependent :-/
$translitExpected = @iconv('UTF-8', 'ASCII//TRANSLIT', 'fränk') ? 'frank' : 'frnk';
return [
['alice', 'alice'],
['b/ob', 'bob'],
['charly🐬', 'charly'],
['debo rah', 'debo_rah'],
['epost@poste.test', 'epost@poste.test'],
['fränk', 'frank'],
['fränk', $translitExpected],
[' gerda ', 'gerda'],
['🕱🐵🐘🐑', null]
];