Skip to content

Commit

Permalink
Make stripAccents working
Browse files Browse the repository at this point in the history
  • Loading branch information
trasher committed Jan 28, 2024
1 parent 654a0b5 commit 5e1e02a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
24 changes: 14 additions & 10 deletions lib/GaletteOAuth2/Authorization/UserHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ public static function getUserData(Container $container, int $id, array $options
//Normalized format s.name (example mail usage : s.name@xxxx.xx )
//FIXME: why don't use email directly?
$norm_login =
mb_substr(self::stripAccents(mb_strtolower($member->surname)), 0, 1) .
mb_substr(self::stripAccents($member->surname), 0, 1) .
'.' .
self::stripAccents(mb_strtolower($nameFPart));
self::stripAccents($nameFPart);

$etat_adhesion = ($member->isActive() && $member->isUp2Date()) || $member->isAdmin();

Expand Down Expand Up @@ -181,7 +181,7 @@ public static function getUserData(Container $container, int $id, array $options
$group = trim($group);
$group = str_replace([' ', '/', '(', ')'], ['_', '', '', ''], $group);
$group = str_replace('__', '_', $group);
$group = mb_strtolower(self::stripAccents($group));
$group = self::stripAccents($group);
}
$groups = implode(',', $groups);

Expand Down Expand Up @@ -245,15 +245,19 @@ public static function mergeOptions(Config $config, $client_id, array $oauth_sco
// 'email' => 'uuuu@ik.me', 'emailVerified' => NULL, 'phone' => NULL,
// 'address' => NULL, 'country' => NULL, 'region' => NULL, 'city' => NULL, 'zip' => NULL

/**
* Strips accented characters, lower string
*
* @param string $str
* @return string
*/
public static function stripAccents(string $str): string
{
//FIXME: there is probably a better way to go.
//try with something like transliterator_transliterate("Any-Latin; Latin-ASCII; [^a-zA-Z0-9\.\ -_] Remove;", $str);
//see https://www.matthecat.com/supprimer-les-accents-d-une-chaine-avec-php.html and https://stackoverflow.com/a/35177682
return strtr(
$str,
'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïñòóôõöøùúûüýÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬĭĮįİıIJijĴĵĶķĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƒƠơƯưǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǺǻǼǽǾǿ',
'AAAAAAAECEEEEIIIIDNOOOOOOUUUUYsaaaaaaaeceeeeiiiinoooooouuuuyyAaAaAaCcCcCcCcDdDdEeEeEeEeEeGgGgGgGgHhHhIiIiIiIiIiIJijJjKkLlLlLlLlllNnNnNnnOoOoOoOEoeRrRrRrSsSsSsSsTtTtTtUuUuUuUuUuUuWwYyYZzZzZzsfOoUuAaIiOoUuUuUuUuUuAaAEaeOo'
return mb_strtolower(
transliterator_transliterate(
"Any-Latin; Latin-ASCII; [^a-zA-Z0-9\.\ -_] Remove;",
$str
)
);
}
}
4 changes: 2 additions & 2 deletions tests/GaletteOAuth2/Authorization/tests/units/UserHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public function testStripAccents(): void
/** @var \Galette\Core\Plugins */
global $plugins;

$str = "éè";
$this->assertSame('ee', \GaletteOAuth2\Authorization\UserHelper::stripAccents($str));
$str = "çéè-ßØ";
$this->assertSame('cee-sso', \GaletteOAuth2\Authorization\UserHelper::stripAccents($str));
}

/**
Expand Down

0 comments on commit 5e1e02a

Please sign in to comment.