Summary
The format regex in isValidUsername():
const validFormat = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/;
allows consecutive hyphens (user--name). Most URL slug conventions and username policies disallow -- because it looks like a typo and can clash with CSS/HTML encoding rules.
Fix
Update the regex to prohibit consecutive hyphens:
const validFormat = /^[a-z0-9]([a-z0-9]|-(?!-))*[a-z0-9]$|^[a-z0-9]$/;
Or add an explicit check:
if (username.includes("--")) return { valid: false, error: "Username cannot contain consecutive hyphens" };
File
backend/src/utils/username-validator.ts
Summary
The format regex in
isValidUsername():allows consecutive hyphens (
user--name). Most URL slug conventions and username policies disallow--because it looks like a typo and can clash with CSS/HTML encoding rules.Fix
Update the regex to prohibit consecutive hyphens:
Or add an explicit check:
File
backend/src/utils/username-validator.ts