From 47a10bd25aadae5774fb4c011810c9d4edc53949 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Mon, 5 Mar 2018 14:03:08 +0100 Subject: treat iconv issues Signed-off-by: Arthur Schiwon --- apps/user_ldap/lib/Access.php | 13 +++++++++---- apps/user_ldap/tests/AccessTest.php | 5 ++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/apps/user_ldap/lib/Access.php b/apps/user_ldap/lib/Access.php index 4ae7dbe4d25..0cbe8fd3028 100644 --- a/apps/user_ldap/lib/Access.php +++ b/apps/user_ldap/lib/Access.php @@ -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); diff --git a/apps/user_ldap/tests/AccessTest.php b/apps/user_ldap/tests/AccessTest.php index c52b8e6611b..336b92af04f 100644 --- a/apps/user_ldap/tests/AccessTest.php +++ b/apps/user_ldap/tests/AccessTest.php @@ -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] ]; -- cgit v1.2.3