Browse Source

treat iconv issues

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
tags/v14.0.0beta1
Arthur Schiwon 6 years ago
parent
commit
47a10bd25a
No account linked to committer's email address
2 changed files with 13 additions and 5 deletions
  1. 9
    4
      apps/user_ldap/lib/Access.php
  2. 4
    1
      apps/user_ldap/tests/AccessTest.php

+ 9
- 4
apps/user_ldap/lib/Access.php View File

* @throws \InvalidArgumentException * @throws \InvalidArgumentException
*/ */
public function sanitizeUsername($name) { public function sanitizeUsername($name) {
$name = trim($name);

if($this->connection->ldapIgnoreNamingRules) { 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 // Replacements
$name = str_replace(' ', '_', $name); $name = str_replace(' ', '_', $name);

+ 4
- 1
apps/user_ldap/tests/AccessTest.php View File

} }


public function intUsernameProvider() { public function intUsernameProvider() {
// system dependent :-/
$translitExpected = @iconv('UTF-8', 'ASCII//TRANSLIT', 'fränk') ? 'frank' : 'frnk';

return [ return [
['alice', 'alice'], ['alice', 'alice'],
['b/ob', 'bob'], ['b/ob', 'bob'],
['charly🐬', 'charly'], ['charly🐬', 'charly'],
['debo rah', 'debo_rah'], ['debo rah', 'debo_rah'],
['epost@poste.test', 'epost@poste.test'], ['epost@poste.test', 'epost@poste.test'],
['fränk', 'frank'],
['fränk', $translitExpected],
[' gerda ', 'gerda'], [' gerda ', 'gerda'],
['🕱🐵🐘🐑', null] ['🕱🐵🐘🐑', null]
]; ];

Loading…
Cancel
Save