From 2316002cd89e50a077d98fa6a9aff52dafe1de91 Mon Sep 17 00:00:00 2001 From: Madeline <46743919+MaddyUnderStars@users.noreply.github.com> Date: Sun, 24 Apr 2022 15:09:45 +1000 Subject: Categories skip most of the ALLOW_INVALID_CHANNEL_NAMES checks on discord.com ( they also trim whitespace ) --- util/src/entities/Channel.ts | 24 ++++++++++++++++-------- util/src/util/InvisibleCharacters.ts | 2 +- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/util/src/entities/Channel.ts b/util/src/entities/Channel.ts index 98766a9d..bf72994f 100644 --- a/util/src/entities/Channel.ts +++ b/util/src/entities/Channel.ts @@ -3,7 +3,7 @@ import { BaseClass } from "./BaseClass"; import { Guild } from "./Guild"; import { PublicUserProjection, User } from "./User"; import { HTTPError } from "lambert-server"; -import { containsAll, emitEvent, getPermission, Snowflake, trimSpecial, InvisibleCharacters } from "../util"; +import { containsAll, emitEvent, getPermission, Snowflake, trimSpecial, InvisibleCharacters, ChannelTypes } from "../util"; import { ChannelCreateEvent, ChannelRecipientRemoveEvent } from "../interfaces"; import { Recipient } from "./Recipient"; import { Message } from "./Message"; @@ -147,7 +147,7 @@ export class Channel extends BaseClass { orphanedRowAction: "delete", }) webhooks?: Webhook[]; - + // TODO: DM channel static async createChannel( channel: Partial, @@ -173,12 +173,20 @@ export class Channel extends BaseClass { if (channel.name.includes(character)) throw new HTTPError("Channel name cannot include invalid characters", 403); - if (channel.name.match(/\-\-+/g)) - throw new HTTPError("Channel name cannot include multiple adjacent dashes.", 403) + // Categories skip these checks on discord.com + if (channel.type !== ChannelType.GUILD_CATEGORY) { + if (channel.name.includes(" ")) + throw new HTTPError("Channel name cannot include invalid characters", 403); + + if (channel.name.match(/\-\-+/g)) + throw new HTTPError("Channel name cannot include multiple adjacent dashes.", 403); - if (channel.name.charAt(0) === "-" || - channel.name.charAt(channel.name.length - 1) === "-") - throw new HTTPError("Channel name cannot start/end with dash.", 403) + if (channel.name.charAt(0) === "-" || + channel.name.charAt(channel.name.length - 1) === "-") + throw new HTTPError("Channel name cannot start/end with dash.", 403); + } + else + channel.name = channel.name.trim(); //category names are trimmed client side on discord.com } if (!guild.features.includes("ALLOW_UNNAMED_CHANNELS")) { @@ -297,7 +305,7 @@ export class Channel extends BaseClass { await emitEvent({ event: "CHANNEL_CREATE", data: channel_dto, user_id: creator_user_id }); } - if (recipients.length === 1) return channel_dto; + if (recipients.length === 1) return channel_dto; else return channel_dto.excludedRecipients([creator_user_id]); } diff --git a/util/src/util/InvisibleCharacters.ts b/util/src/util/InvisibleCharacters.ts index 2b014e14..a48cfab0 100644 --- a/util/src/util/InvisibleCharacters.ts +++ b/util/src/util/InvisibleCharacters.ts @@ -1,7 +1,7 @@ // List from https://invisible-characters.com/ export const InvisibleCharacters = [ '\u{9}', //Tab - '\u{20}', //Space + //'\u{20}', //Space //categories can have spaces in them '\u{ad}', //Soft hyphen '\u{34f}', //Combining grapheme joiner '\u{61c}', //Arabic letter mark -- cgit 1.4.1 From eca65393e892204020957ecbaf0fffb1092d433f Mon Sep 17 00:00:00 2001 From: Erkin Alp Güney Date: Sun, 24 Apr 2022 09:10:22 +0300 Subject: make it configurable by guild feature flag --- util/src/entities/Channel.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/src/entities/Channel.ts b/util/src/entities/Channel.ts index bf72994f..eb19cbbe 100644 --- a/util/src/entities/Channel.ts +++ b/util/src/entities/Channel.ts @@ -174,7 +174,7 @@ export class Channel extends BaseClass { throw new HTTPError("Channel name cannot include invalid characters", 403); // Categories skip these checks on discord.com - if (channel.type !== ChannelType.GUILD_CATEGORY) { + if (channel.type !== ChannelType.GUILD_CATEGORY || guild.features.includes("IRC_LIKE_CATEGORY_NAMES")) { if (channel.name.includes(" ")) throw new HTTPError("Channel name cannot include invalid characters", 403); -- cgit 1.4.1 From 615bd4730e46591e3cbb3f489821cdf33dcc3d60 Mon Sep 17 00:00:00 2001 From: Erkin Alp Güney Date: Sun, 24 Apr 2022 09:13:57 +0300 Subject: removed char joiners as they are actually useful, added page break --- util/src/util/InvisibleCharacters.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/util/src/util/InvisibleCharacters.ts b/util/src/util/InvisibleCharacters.ts index a48cfab0..a58c8c7c 100644 --- a/util/src/util/InvisibleCharacters.ts +++ b/util/src/util/InvisibleCharacters.ts @@ -1,9 +1,10 @@ // List from https://invisible-characters.com/ export const InvisibleCharacters = [ '\u{9}', //Tab + '\u{c}', //Form feed //'\u{20}', //Space //categories can have spaces in them '\u{ad}', //Soft hyphen - '\u{34f}', //Combining grapheme joiner + // '\u{34f}', //Combining grapheme joiner '\u{61c}', //Arabic letter mark '\u{115f}', //Hangul choseong filler '\u{1160}', //Hangul jungseong filler @@ -23,12 +24,12 @@ export const InvisibleCharacters = [ '\u{200a}', //Hair space '\u{200b}', //Zero width space '\u{200c}', //Zero width non-joiner - '\u{200d}', //Zero width joiner + // '\u{200d}', //Zero width joiner '\u{200e}', //Left-to-right mark '\u{200f}', //Right-to-left mark '\u{202f}', //Narrow no-break space '\u{205f}', //Medium mathematical space - '\u{2060}', //Word joiner + // '\u{2060}', //Word joiner -- WJ is required in some languages that don't use spaces to split words '\u{2061}', //Function application '\u{2062}', //Invisible times '\u{2063}', //Invisible separator @@ -53,4 +54,4 @@ export const InvisibleCharacters = [ '\u{1d178}', //Musical symbol end slur '\u{1d179}', //Musical symbol begin phrase '\u{1d17a}' //Musical symbol end phrase -]; \ No newline at end of file +]; -- cgit 1.4.1