From 62636c7eb315ad997bf58e2281d2ad93a7ae4d53 Mon Sep 17 00:00:00 2001 From: Waleed Date: Thu, 14 May 2026 19:49:30 -0700 Subject: [PATCH] improvement(gmail): replace custom html-to-text regex with library (#4613) * improvement(gmail): replace custom html-to-text regex with html-to-text library Resolves 4 CodeQL alerts on htmlToPlainText (incomplete tag/entity handling, unsafe regex backtracking). Delegates to the html-to-text npm package already used by the outlook polling trigger and the mail/send route. * improvement(gmail): match outlook selectors config, add nbsp/anchor tests Aligns html-to-text options with apps/sim/lib/webhooks/polling/outlook.ts: suppress anchor hrefs when identical to text, drop bare # anchors, skip img/script/style content. Adds tests for nbsp preservation and anchor behavior. --- apps/sim/tools/gmail/utils.test.ts | 19 ++++++++++++++---- apps/sim/tools/gmail/utils.ts | 32 +++++++++++++----------------- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/apps/sim/tools/gmail/utils.test.ts b/apps/sim/tools/gmail/utils.test.ts index 2b56007bf0..2b0d226c5e 100644 --- a/apps/sim/tools/gmail/utils.test.ts +++ b/apps/sim/tools/gmail/utils.test.ts @@ -81,9 +81,9 @@ describe('plainTextToHtml', () => { }) describe('htmlToPlainText', () => { - it('strips tags, decodes entities, and collapses whitespace', () => { + it('strips tags and decodes entities', () => { const result = htmlToPlainText('

Hi & bye

Line
break

') - expect(result).toBe('Hi & bye\nLine\nbreak') + expect(result).toBe('Hi & bye\n\nLine\nbreak') }) it('drops