impr(server): dont allow dots in usernames

This commit is contained in:
Miodec 2024-07-03 15:03:07 +02:00
parent 8beddebbd4
commit dd4943bae0
3 changed files with 3 additions and 14 deletions

View file

@ -16,10 +16,6 @@ describe("Validation", () => {
name: "valid-name",
expected: true,
},
{
name: "valid.name",
expected: true,
},
{
name: "thistagnameistoolong",
expected: false,
@ -97,7 +93,7 @@ describe("Validation", () => {
expected: true,
},
{
name: "Fe-rotiq._123._",
name: "Fe-rotiq_123_",
expected: true,
},
{

View file

@ -83,7 +83,7 @@ const usernameValidation = joi
"string.profanity":
"The username contains profanity. If you believe this is a mistake, please contact us ",
"string.pattern.base":
"Username invalid. Name cannot use special characters or contain more than 16 characters. Can include _ . and - ",
"Username invalid. Name cannot use special characters or contain more than 16 characters. Can include _ and - ",
});
const languageSchema = joi

View file

@ -8,20 +8,13 @@ export function inRange(value: number, min: number, max: number): boolean {
return value >= min && value <= max;
}
const VALID_NAME_PATTERN = /^[\da-zA-Z_.-]+$/;
const VALID_NAME_PATTERN = /^[\da-zA-Z_-]+$/;
export function isUsernameValid(name: string): boolean {
if (_.isNil(name) || !inRange(name.length, 1, 16)) {
return false;
}
const normalizedName = name.toLowerCase();
const beginsWithPeriod = /^\..*/.test(normalizedName);
if (beginsWithPeriod) {
return false;
}
return VALID_NAME_PATTERN.test(name);
}