diff --git a/src/usersyncroniser.ts b/src/usersyncroniser.ts index b82722d8cd6dde818dca6c86c791c584b69b8ab6..51ac3fc02cd30ad71c06f3064de9d40e2737792c 100644 --- a/src/usersyncroniser.ts +++ b/src/usersyncroniser.ts @@ -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, diff --git a/src/util.ts b/src/util.ts index f09190ea9fe3dcd9bdf3383246fc822c6328f491..b5345c81ce3fa4b6a082c4b1b98b5b51b1cdcb7c 100644 --- a/src/util.ts +++ b/src/util.ts @@ -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()}`) } } diff --git a/tsconfig.json b/tsconfig.json index d8273e20684e78cffa6202d9d332cdc835583039..b2d7054f301ae3fe6d653423f606c19f17022556 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "module": "commonjs", "moduleResolution": "node", - "target": "es2016", + "target": "es2021", "noImplicitAny": false, "inlineSourceMap": true, "outDir": "./build",