Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 8c07fc13 rédigé par Elliu's avatar Elliu Validation de salixor
Parcourir les fichiers

Properly clean discord webhooks username

parent 0e85f7b5
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -317,7 +317,7 @@ export class UserSyncroniser {
// for webhooks we append the username to the mxid, as webhooks with the same
// id can have multiple different usernames set. This way we don't spam
// userstate changes
mxidExtra = "_" + Util.ParseMxid(`@${user.username}`, false).localpart;
mxidExtra = "_" + Util.ParseMxid(`@${user.username}`).localpart;
}
const guildState: IGuildMemberState = Object.assign({}, DEFAULT_GUILD_STATE, {
bot: user.bot,
......
......@@ -365,10 +365,7 @@ export class Util {
const badChars = new Set(localpart.replace(/([a-z0-9]|-|\.|=|_)+/g, ""));
badChars.forEach((c) => {
const hex = c.charCodeAt(0).toString(RADIX).toLowerCase();
localpart = localpart.replace(
new RegExp(`\\${c}`, "g"),
`=${hex}`,
);
localpart = localpart.replaceAll(c, `=${hex}`);
});
}
return {
......@@ -380,17 +377,7 @@ export class Util {
// Taken from https://github.com/matrix-org/matrix-appservice-bridge/blob/master/lib/models/users/matrix.js
public static EscapeStringForUserId(localpart: string) {
// NOTE: Currently Matrix accepts / in the userId, although going forward it will be removed.
const badChars = new Set(localpart.replace(/([a-z]|[0-9]|-|\.|=|_)+/g, ""));
let res = localpart;
badChars.forEach((c) => {
const hex = c.charCodeAt(0).toString(16).toLowerCase();
res = res.replace(
new RegExp(`\\x${hex}`, "g"),
`=${hex}`,
);
});
return res;
return localpart.replace(/[^a-z0-9-._]/g, a => `=${a.codePointAt(0)!.toString(16).toLowerCase()}`)
}
}
......
......@@ -2,7 +2,7 @@
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "node",
"target": "es2016",
"target": "es2021",
"noImplicitAny": false,
"inlineSourceMap": true,
"outDir": "./build",
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter