Skip to content

Commit

Permalink
Fix broken webhooks
Browse files Browse the repository at this point in the history
Some webhooks were never sent on matrix side, because they contained non-alphanumeric characters. This should fix the issue
  • Loading branch information
hellcp authored May 24, 2022
1 parent cbd3c67 commit 925e469
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,19 +378,8 @@ 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()}`);
}
}

Expand Down

0 comments on commit 925e469

Please # to comment.