Improve username generator (handle unicode conversion properly)

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2019-10-12 18:11:10 +02:00
parent bd6773139c
commit 6862d34965
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773

View file

@ -304,9 +304,13 @@ export default class EditIdentity extends Vue {
private convertToUsername(value: string | null) {
if (!value) return '';
return value.toLowerCase()
// https://stackoverflow.com/a/37511463
return value.toLocaleLowerCase()
.normalize('NFD')
.replace(/[\u0300-\u036f]/g, '')
.replace(/ /g, '_')
.replace(/[^a-z0-9._]/g, '');
.replace(/[^a-z0-9._]/g, '')
;
}
private async buildVariables() {