diff options
author | blizzz <blizzz@arthur-schiwon.de> | 2021-11-29 11:37:19 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-29 11:37:19 +0100 |
commit | 84e47fb4841fcd6b59e0b8ef9b84264d1da6b3d6 (patch) | |
tree | 89c64255050d47c649faf2cb07f6fa26907bd33f /apps/user_ldap | |
parent | 03b424af19f187f0988b96b16e548928940610c9 (diff) | |
parent | 480056de88b3a8205ff584e4950a6c117f991737 (diff) | |
download | nextcloud-server-84e47fb4841fcd6b59e0b8ef9b84264d1da6b3d6.tar.gz nextcloud-server-84e47fb4841fcd6b59e0b8ef9b84264d1da6b3d6.zip |
Merge pull request #29470 from nextcloud/fix/translit-php8
Avoid use of iconv to get rid of unicode
Diffstat (limited to 'apps/user_ldap')
-rw-r--r-- | apps/user_ldap/lib/Access.php | 15 | ||||
-rw-r--r-- | apps/user_ldap/tests/AccessTest.php | 9 |
2 files changed, 11 insertions, 13 deletions
diff --git a/apps/user_ldap/lib/Access.php b/apps/user_ldap/lib/Access.php index 7b7ae74d3f3..0af04747ded 100644 --- a/apps/user_ldap/lib/Access.php +++ b/apps/user_ldap/lib/Access.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); diff --git a/apps/user_ldap/tests/AccessTest.php b/apps/user_ldap/tests/AccessTest.php index ef58db00f76..e1f262165f5 100644 --- a/apps/user_ldap/tests/AccessTest.php +++ b/apps/user_ldap/tests/AccessTest.php @@ -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); } |