Skip to content

Commit 02b88f9

Browse files
committed
fix(gmail): decode & last in htmlToPlainText to avoid double-decoding compound entities
1 parent 8d9d465 commit 02b88f9

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

apps/sim/tools/gmail/utils.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ describe('htmlToPlainText', () => {
7575
it('drops <style> and <script> contents', () => {
7676
expect(htmlToPlainText('<style>p{}</style><p>Hi</p>')).toBe('Hi')
7777
})
78+
79+
it('does not double-decode compound entities like &amp;lt;', () => {
80+
expect(htmlToPlainText('<p>&amp;lt; is the literal &lt; entity</p>')).toBe(
81+
'&lt; is the literal < entity'
82+
)
83+
})
7884
})
7985

8086
describe('buildSimpleEmailMessage', () => {

apps/sim/tools/gmail/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,11 +356,11 @@ export function htmlToPlainText(html: string): string {
356356
.replace(/<\/(p|div|h[1-6]|li|tr)>/gi, '\n')
357357
.replace(/<[^>]+>/g, '')
358358
.replace(/&nbsp;/g, ' ')
359-
.replace(/&amp;/g, '&')
360359
.replace(/&lt;/g, '<')
361360
.replace(/&gt;/g, '>')
362361
.replace(/&quot;/g, '"')
363362
.replace(/&#39;/g, "'")
363+
.replace(/&amp;/g, '&')
364364
.replace(/\n{3,}/g, '\n\n')
365365
.trim()
366366
}

0 commit comments

Comments
 (0)