1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-10 12:42:44 +01:00

* Replaced list of invisible characters with unicode codepoints

* No longer silently edit invalid channel names
* No longer trim channel names in unnamed check
This commit is contained in:
Madeline 2022-01-15 18:48:22 +11:00 committed by Erkin Alp Güney
parent 0a53860645
commit f8f236afb2
2 changed files with 65 additions and 62 deletions

View File

@ -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);
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.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 (!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);
}
}

View File

@ -1,55 +1,56 @@
// List from https://invisible-characters.com/
export const InvisibleCharacters = [
"\t",
" ",
"­",
"͏",
"؜",
"",
"",
"",
"",
"",
" ",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
" ",
"",
"",
"",
"",
"𝅙",
"𝅳",
"𝅴",
"𝅵",
"𝅶",
"𝅷",
"𝅸",
"𝅹",
"𝅺"
]
'\u{9}', //Tab
'\u{20}', //Space
'\u{ad}', //Soft hyphen
'\u{34f}', //Combining grapheme joiner
'\u{61c}', //Arabic letter mark
'\u{115f}', //Hangul choseong filler
'\u{1160}', //Hangul jungseong filler
'\u{17b4}', //Khmer vowel inherent AQ
'\u{17b5}', //Khmer vowel inherent AA
'\u{180e}', //Mongolian vowel separator
'\u{2000}', //En quad
'\u{2001}', //Em quad
'\u{2002}', //En space
'\u{2003}', //Em space
'\u{2004}', //Three-per-em space
'\u{2005}', //Four-per-em space
'\u{2006}', //Six-per-em space
'\u{2007}', //Figure space
'\u{2008}', //Punctuation space
'\u{2009}', //Thin space
'\u{200a}', //Hair space
'\u{200b}', //Zero width space
'\u{200c}', //Zero width non-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{2061}', //Function application
'\u{2062}', //Invisible times
'\u{2063}', //Invisible separator
'\u{2064}', //Invisible plus
'\u{206a}', //Inhibit symmetric swapping
'\u{206b}', //Activate symmetric swapping
'\u{206c}', //Inhibit arabic form shaping
'\u{206d}', //Activate arabic form shaping
'\u{206e}', //National digit shapes
'\u{206f}', //Nominal digit shapes
'\u{3000}', //Ideographic space
'\u{2800}', //Braille pattern blank
'\u{3164}', //Hangul filler
'\u{feff}', //Zero width no-break space
'\u{ffa0}', //Haldwidth hangul filler
'\u{1d159}', //Musical symbol null notehead
'\u{1d173}', //Musical symbol begin beam
'\u{1d174}', //Musical symbol end beam
'\u{1d175}', //Musical symbol begin tie
'\u{1d176}', //Musical symbol end tie
'\u{1d177}', //Musical symbol begin slur
'\u{1d178}', //Musical symbol end slur
'\u{1d179}', //Musical symbol begin phrase
'\u{1d17a}' //Musical symbol end phrase
];