fedimbed: fix where its actually crashing and also slight optimization

This commit is contained in:
Cynthia Foxwell 2023-11-22 14:24:44 -07:00
parent 6bff2e9eb3
commit 99510766d4

View file

@ -724,10 +724,15 @@ events.add("messageCreate", "fedimbed", async function (msg) {
.trim()
.replace("@\u200b", "@")
.replace("@%E2%80%8B", "@");
let urlObj;
try {
urlObj = new URL(url);
} catch {
// noop
}
for (const service of Object.keys(PATH_REGEX)) {
const regex = PATH_REGEX[service];
const urlObj = new URL(url);
if (regex.test(urlObj.pathname)) {
if (urlObj && regex.test(urlObj.pathname)) {
logger.verbose(
"fedimbed",
`Hit "${service}" for "${url}", processing now.`