Skip to content

Commit 01fb3df

Browse files
Update username.ts
missing characters will be replaced with a random alphanumeric sequence instead of "x", making usernames more unique.
1 parent 3ce5785 commit 01fb3df

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/core/validations/username.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ export function validateUsername(username: string): {
7171
}
7272

7373
export function sanitizeUsername(str: string): string {
74-
const sanitized = str
75-
.replace(/[^a-zA-Z0-9_\[\] 🐈🍀]/gu, "")
76-
.slice(0, MAX_USERNAME_LENGTH);
77-
return sanitized.padEnd(MIN_USERNAME_LENGTH, "x");
74+
let sanitized = str.replace(/[^a-zA-Z0-9_\[\] 🐈🍀]/gu, "");
75+
if (sanitized.length < MIN_USERNAME_LENGTH) {
76+
sanitized += Math.random().toString(36).substring(2, 2 + MIN_USERNAME_LENGTH - sanitized.length);
77+
}
78+
return sanitized.slice(0, MAX_USERNAME_LENGTH);
7879
}

0 commit comments

Comments
 (0)