From b0d08e21828e46e741d717fe8013836b41b09aea Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Mon, 5 Sep 2022 10:40:45 +0100 Subject: [PATCH] Ensure we replace all matches --- src/Connections/GenericHook.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Connections/GenericHook.ts b/src/Connections/GenericHook.ts index 91b9d171..24aa0bf5 100644 --- a/src/Connections/GenericHook.ts +++ b/src/Connections/GenericHook.ts @@ -355,6 +355,7 @@ export class GenericHookConnection extends BaseConnection implements IConnection log.debug(`Media ${uuid} requested but not used`); continue; } + const regExp = new RegExp(uuid, 'g'); try { const content = await axios.get(mediaurl, { timeout: GET_MEDIA_TIMEOUT, @@ -363,9 +364,9 @@ export class GenericHookConnection extends BaseConnection implements IConnection } }) const mxcUri = await this.as.botClient.uploadContent(content.data, content.headers['content-type']); - plain = plain.replace(uuid, mxcUri); + plain = plain.replace(regExp, mxcUri); if (transformationResult.html) { - transformationResult.html = transformationResult.html.replace(transformationResult.html, mxcUri); + transformationResult.html = transformationResult.html.replace(regExp, mxcUri); } } catch (ex) { log.warn(`Failed to fetch media for transformation`, {mediaurl});