From 53c559c001577afbf2e1910f7510093f7c1371ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Acid=20Chicken=20=28=E7=A1=AB=E9=85=B8=E9=B6=8F=29?= Date: Sat, 1 Dec 2018 07:19:17 +0900 Subject: [PATCH] Allow hyphens in the middle of remote usernames (#3440) * Allow hyphens in the middle of remote usernames refs: d797c29db462de4a3d69a5077a1ae4d03195b6f2 * Make options fallback better * Make options flat --- src/models/user.ts | 4 ++-- src/remote/activitypub/models/person.ts | 2 +- src/server/api/endpoints/users/search.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/models/user.ts b/src/models/user.ts index db10e06d8a..0e9875504b 100644 --- a/src/models/user.ts +++ b/src/models/user.ts @@ -147,8 +147,8 @@ export const isRemoteUser = (user: any): user is IRemoteUser => !isLocalUser(user); //#region Validators -export function validateUsername(username: string): boolean { - return typeof username == 'string' && /^[a-zA-Z0-9_]{1,20}$/.test(username); +export function validateUsername(username: string, remote?: boolean): boolean { + return typeof username == 'string' && (remote ? /^\w+([\w\.-]+\w+)?$/ : /^[a-zA-Z0-9_]{1,20}$/).test(username); } export function validatePassword(password: string): boolean { diff --git a/src/remote/activitypub/models/person.ts b/src/remote/activitypub/models/person.ts index 6f694a6ec1..74fcdc10a2 100644 --- a/src/remote/activitypub/models/person.ts +++ b/src/remote/activitypub/models/person.ts @@ -43,7 +43,7 @@ function validatePerson(x: any, uri: string) { return new Error('invalid person: inbox is not a string'); } - if (!validateUsername(x.preferredUsername)) { + if (!validateUsername(x.preferredUsername, true)) { return new Error('invalid person: invalid username'); } diff --git a/src/server/api/endpoints/users/search.ts b/src/server/api/endpoints/users/search.ts index b37c07003b..85138fa6e1 100644 --- a/src/server/api/endpoints/users/search.ts +++ b/src/server/api/endpoints/users/search.ts @@ -45,7 +45,7 @@ export const meta = { }; export default define(meta, (ps, me) => new Promise(async (res, rej) => { - const isUsername = validateUsername(ps.query.replace('@', '')); + const isUsername = validateUsername(ps.query.replace('@', ''), true); let users: IUser[] = [];