summary refs log tree commit diff
path: root/util/src/entities
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-01-15 18:48:22 +1100
committerErkin Alp Güney <erkinalp9035@gmail.com>2022-01-23 23:29:14 +0300
commit8f87d2ceedb4831e17a1ecaf7fe3be3cfa1bb2df (patch)
treec912b4c3006ac2e7156762f62b4778b6131f4f96 /util/src/entities
parentchannel.owner_id is type string not number (diff)
downloadserver-8f87d2ceedb4831e17a1ecaf7fe3be3cfa1bb2df.tar.xz
* Replaced list of invisible characters with unicode codepoints
* No longer silently edit invalid channel names
* No longer trim channel names in unnamed check
Diffstat (limited to 'util/src/entities')
-rw-r--r--util/src/entities/Channel.ts18
1 files changed, 10 insertions, 8 deletions
diff --git a/util/src/entities/Channel.ts b/util/src/entities/Channel.ts
index 6750a002..1cc4a538 100644
--- a/util/src/entities/Channel.ts
+++ b/util/src/entities/Channel.ts
@@ -162,19 +162,21 @@ export class Channel extends BaseClass {
 		if (!opts?.skipNameChecks) {

 			const guild = await Guild.findOneOrFail({ id: channel.guild_id });

 			if (!guild.features.includes("ALLOW_INVALID_CHANNEL_NAMES") && channel.name) {

-

 				for (var character of InvisibleCharacters)

-					channel.name = channel.name.split(character).join("-");

+					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)

 

-				channel.name = channel.name.split(/\-+/g).join("-");	//replace multiple occurances with just one

-				channel.name = channel.name.split("-").filter(Boolean).join("-");	//trim '-' character

+				if (channel.name.charAt(0) === "-" ||

+					channel.name.charAt(channel.name.length - 1) === "-")

+					throw new HTTPError("Channel name cannot start/end with dash.", 403)

 			}

 

 			if (!guild.features.includes("ALLOW_UNNAMED_CHANNELS")) {

-

-				if (channel.name) channel.name = channel.name.trim();

-

-				if (!channel.name) throw new HTTPError("Channel name cannot be empty.");

+				if (!channel.name)

+					throw new HTTPError("Channel name cannot be empty.", 403);

 			}

 		}