diff --git a/forum/profil.py b/forum/profil.py index 9ffa5ba..6a12452 100644 --- a/forum/profil.py +++ b/forum/profil.py @@ -35,6 +35,13 @@ class UsernameInvalide(ValueError): _LEET = str.maketrans({"0": "o", "1": "i", "3": "e", "4": "a", "5": "s", "7": "t", "@": "a", "$": "s", "!": "i"}) +def _latin_ou_chiffre(c): + """Chiffre 0-9 ou lettre de l'alphabet latin (accents compris) : bloque les sosies cyrilliques ou grecs.""" + if "0" <= c <= "9": + return True + return c.isalpha() and unicodedata.name(c, "").startswith("LATIN ") + + def cle(texte): """Minuscules, sans accents, lettres et chiffres seulement (séparateurs retirés).""" s = unicodedata.normalize("NFKD", (texte or "").casefold()) @@ -93,7 +100,7 @@ def verifier_username(brut): raise UsernameInvalide("Trop long : %d caractères maximum." % USERNAME_MAX) mauvais = [] for c in u: - if not (c.isalnum() or c in SPECIAUX) and c not in mauvais: + if not (_latin_ou_chiffre(c) or c in SPECIAUX) and c not in mauvais: mauvais.append(c) if mauvais: raise UsernameInvalide("Caractère non accepté : « %s ». Lettres, chiffres et . @ - _ ! ? ¿ seulement."