summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2021-11-29 17:02:25 +0100
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>2021-12-20 10:00:42 +0000
commit32831de424d7f722edcc4936cf508746d30b22b3 (patch)
tree371bbb287d0ffab032b6b77cb2060470d51d5389
parente259f6e20ee930c382e9aa9cdd2cfe935d1ba3c2 (diff)
downloadnextcloud-server-32831de424d7f722edcc4936cf508746d30b22b3.tar.gz
nextcloud-server-32831de424d7f722edcc4936cf508746d30b22b3.zip
[stable23] Avoid use of iconv to get rid of unicode
Using iconv for translit depends upon server configuration, locale, and PHP version. Using htmlentities instead to have a consistent behavior independent of configuration. Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com> Co-authored-by: MichaIng <micha@dietpi.com>
-rw-r--r--apps/user_ldap/lib/Access.php15
-rw-r--r--apps/user_ldap/tests/AccessTest.php9
2 files changed, 11 insertions, 13 deletions
diff --git a/apps/user_ldap/lib/Access.php b/apps/user_ldap/lib/Access.php
index 8f39e22117b..88146d21062 100644
--- a/apps/user_ldap/lib/Access.php
+++ b/apps/user_ldap/lib/Access.php
@@ -1434,12 +1434,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 4d4f92770f6..8a389853c28 100644
--- a/apps/user_ldap/tests/AccessTest.php
+++ b/apps/user_ldap/tests/AccessTest.php
@@ -691,16 +691,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],
[
@@ -734,9 +732,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);
}