Browse Source
Merge pull request #29470 from nextcloud/fix/translit-php8
Avoid use of iconv to get rid of unicode
pull/29951/head
blizzz
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
11 additions and
13 deletions
-
apps/user_ldap/lib/Access.php
-
apps/user_ldap/tests/AccessTest.php
|
|
|
@ -1433,12 +1433,15 @@ class Access extends LDAPUtility { |
|
|
|
return $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; |
|
|
|
} |
|
|
|
// Use htmlentities to get rid of accents
|
|
|
|
$name = htmlentities($name, ENT_NOQUOTES, 'UTF-8'); |
|
|
|
|
|
|
|
// Remove accents
|
|
|
|
$name = preg_replace('#&([A-Za-z])(?:acute|cedil|caron|circ|grave|orn|ring|slash|th|tilde|uml);#', '\1', $name); |
|
|
|
// Remove ligatures
|
|
|
|
$name = preg_replace('#&([A-Za-z]{2})(?:lig);#', '\1', $name); |
|
|
|
// Remove unknown leftover entities
|
|
|
|
$name = preg_replace('#&[^;]+;#', '', $name); |
|
|
|
|
|
|
|
// Replacements
|
|
|
|
$name = str_replace(' ', '_', $name); |
|
|
|
|
|
|
|
@ -688,16 +688,14 @@ 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', $translitExpected], |
|
|
|
['fränk', 'frank'], |
|
|
|
[' UPPÉR Case/[\]^`', 'UPPER_Case'], |
|
|
|
[' gerda ', 'gerda'], |
|
|
|
['🕱🐵🐘🐑', null], |
|
|
|
[ |
|
|
|
@ -731,9 +729,6 @@ class AccessTest extends TestCase { |
|
|
|
* @param $expected |
|
|
|
*/ |
|
|
|
public function testSanitizeUsername($name, $expected) { |
|
|
|
if ($name === 'fränk' && PHP_MAJOR_VERSION > 7) { |
|
|
|
$this->markTestSkipped('Special chars do boom still on CI in php8'); |
|
|
|
} |
|
|
|
if ($expected === null) { |
|
|
|
$this->expectException(\InvalidArgumentException::class); |
|
|
|
} |
|
|
|
|