Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable21] [stable23] Avoid use of iconv to get rid of unicode #30348

Merged
merged 1 commit into from
Dec 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
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