From 85c26dc06309104ee56ea6216266185afd7e979c Mon Sep 17 00:00:00 2001 From: Debian Date: Mon, 19 Sep 2022 15:49:11 +0000 Subject: Small fix for tag digit and undefined email --- util/src/entities/Member.ts | 8 +++++++- util/src/entities/User.ts | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/util/src/entities/Member.ts b/util/src/entities/Member.ts index 8529398b..c2bc65c4 100644 --- a/util/src/entities/Member.ts +++ b/util/src/entities/Member.ts @@ -74,7 +74,13 @@ export class Member extends BaseClassWithoutId { nick?: string; setNick(val: string) { - if (val && BannedWords.find(val)) throw FieldErrors({ nick: { message: "Bad nickname", code: "INVALID_NICKNAME" } }); + + if (val) { + val = val.split("\n").join(""); + val = val.split("\t").join(""); + if (BannedWords.find(val)) throw FieldErrors({ nick: { message: "Bad nickname", code: "INVALID_NICKNAME" } }); + } + this.nick = val; } diff --git a/util/src/entities/User.ts b/util/src/entities/User.ts index 230d6d82..5f864d8f 100644 --- a/util/src/entities/User.ts +++ b/util/src/entities/User.ts @@ -69,8 +69,10 @@ export class User extends BaseClass { setDiscriminator(val: string) { const number = Number(val); + if (val.length > 4) throw new Error("invalid discriminator"); if (isNaN(number)) throw new Error("invalid discriminator"); if (number <= 0 || number >= 10000) throw new Error("discriminator must be between 1 and 9999"); + val = Number(val).toString() this.discriminator = val.toString().padStart(4, "0"); } @@ -137,6 +139,11 @@ export class User extends BaseClass { @Column({ nullable: true, select: false }) email?: string; // email of the user + setEmail(val: string) { + if (!val.match(/([a-z\d.-]{3,})@([a-z\d.-]+).([a-z]{2,})/g)) throw FieldErrors({ email: { message: "Invalid email", code: "EMAIL_INVALID" } }); + this.email = val; + } + @Column() flags: string; // UserFlags -- cgit 1.4.1 From 4312152d0affd928741b3f7ee92eda02875011d2 Mon Sep 17 00:00:00 2001 From: Madeline <46743919+MaddyUnderStars@users.noreply.github.com> Date: Tue, 20 Sep 2022 16:25:59 +1000 Subject: Add adjustEmail call to setEmail --- util/src/entities/User.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/util/src/entities/User.ts b/util/src/entities/User.ts index 5f864d8f..5ae90c7c 100644 --- a/util/src/entities/User.ts +++ b/util/src/entities/User.ts @@ -3,7 +3,7 @@ import { BaseClass } from "./BaseClass"; import { BitField } from "../util/BitField"; import { Relationship } from "./Relationship"; import { ConnectedAccount } from "./ConnectedAccount"; -import { Config, FieldErrors, Snowflake, trimSpecial, BannedWords } from ".."; +import { Config, FieldErrors, Snowflake, trimSpecial, BannedWords, adjustEmail } from ".."; import { Member, Session } from "."; export enum PublicUserEnum { @@ -72,7 +72,7 @@ export class User extends BaseClass { if (val.length > 4) throw new Error("invalid discriminator"); if (isNaN(number)) throw new Error("invalid discriminator"); if (number <= 0 || number >= 10000) throw new Error("discriminator must be between 1 and 9999"); - val = Number(val).toString() + val = Number(val).toString(); this.discriminator = val.toString().padStart(4, "0"); } @@ -139,10 +139,14 @@ export class User extends BaseClass { @Column({ nullable: true, select: false }) email?: string; // email of the user - setEmail(val: string) { - if (!val.match(/([a-z\d.-]{3,})@([a-z\d.-]+).([a-z]{2,})/g)) throw FieldErrors({ email: { message: "Invalid email", code: "EMAIL_INVALID" } }); - this.email = val; - } + setEmail(val?: string) { + if (val) { + val = adjustEmail(val); + if (!val) throw FieldErrors({ email: { message: "Invalid email", code: "EMAIL_INVALID" } }); + if (!val.match(/([a-z\d.-]{3,})@([a-z\d.-]+).([a-z]{2,})/g)) throw FieldErrors({ email: { message: "Invalid email", code: "EMAIL_INVALID" } }); + } + this.email = val; + } @Column() flags: string; // UserFlags -- cgit 1.4.1