fix numeric / empty username bug

This commit is contained in:
Face 2025-06-08 21:45:12 +03:00
parent 5c95051ddf
commit 1a45c82712
2 changed files with 10 additions and 4 deletions

View file

@ -12,15 +12,16 @@ async function validateInputs(name: string, bio: string, username: string, avata
throw error(400, 'Display name is required');
}
if (name.trim().length < 2) {
const trimmedName = name.trim();
if (trimmedName.length < 2) {
throw error(400, 'Display name must be at least 2 characters');
}
if (name.trim().length > 50) {
if (trimmedName.length > 50) {
throw error(400, 'Display name must be 50 characters or less');
}
if (name && !(await isNameAppropriate(name.trim()))) {
if (!(await isNameAppropriate(trimmedName))) {
throw error(400, 'Name contains inappropriate content');
}
@ -37,6 +38,11 @@ async function validateInputs(name: string, bio: string, username: string, avata
if (!alphanumericRegex.test(username)) {
throw error(400, 'Username must contain only lowercase letters, numbers, and underscores');
}
const purelyNumericRegex = /^\d+$/;
if (purelyNumericRegex.test(username)) {
throw error(400, 'Username cannot be purely numeric');
}
}
if (username && !(await isNameAppropriate(username))) {

View file

@ -125,7 +125,7 @@
try {
const fd = new FormData();
fd.append('name', name);
fd.append('name', name.trim());
fd.append('bio', bio);
fd.append('username', username);
if (avatarFile?.[0]) fd.append('avatar', avatarFile[0]);