Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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 <[email protected]>
  • Loading branch information
come-nc committed Oct 28, 2021
commit 158e73242ee692f398215a9fcbdc6aa60347e396
15 changes: 9 additions & 6 deletions apps/user_ldap/lib/Access.php
Original file line number Diff line number Diff line change
Expand Up @@ -1433,12 +1433,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
8 changes: 1 addition & 7 deletions apps/user_ldap/tests/AccessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -689,16 +689,13 @@ 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'],
[' gerda ', 'gerda'],
['🕱🐵🐘🐑', null],
[
Expand Down Expand Up @@ -732,9 +729,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