Skip to content

Commit

Permalink
Merge pull request #30348 from nextcloud/backport/29965/stable21
Browse files Browse the repository at this point in the history
[stable21] [stable23] Avoid use of iconv to get rid of unicode
  • Loading branch information
MichaIng authored Dec 20, 2021
2 parents 57bb6e7 + 32831de commit c872f2a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
15 changes: 9 additions & 6 deletions apps/user_ldap/lib/Access.php
Original file line number Diff line number Diff line change
Expand Up @@ -1434,12 +1434,15 @@ public function sanitizeUsername($name) {
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);
Expand Down
9 changes: 2 additions & 7 deletions apps/user_ldap/tests/AccessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -691,16 +691,14 @@ public function testFetchListOfGroupsKnown() {
}

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'],
['[email protected]', '[email protected]'],
['fränk', $translitExpected],
['fränk', 'frank'],
[' UPPÉR Case/[\]^`', 'UPPER_Case'],
[' gerda ', 'gerda'],
['🕱🐵🐘🐑', null],
[
Expand Down Expand Up @@ -734,9 +732,6 @@ public function groupIDCandidateProvider() {
* @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);
}
Expand Down

0 comments on commit c872f2a

Please sign in to comment.