fix: omit the base path prefix when it resolves to the root

A caller passing basePath '/' produced //api/email/..., which a browser reads as a protocol-relative URL rather than a path. Strip the slashes first and only add a prefix when something is left.
This commit is contained in:
dualfroz committed 2026-09-17 16:18:50 +02:00
1 parent 8dceaec54a
commit 15ecda681f
3 files changed
+18 -2

No files matched your search

@@ -122,6 +122,20 @@ describe('replaceCidReferences', () => {
}
})
it('should treat basePath "/" as no prefix', () => {
const html = '<img src="cid:image123">'
const attachments = [{ contentId: 'image123', generatedFileName: 'abc.png' }]
const result = replaceCidReferences(html, 'email1', attachments, undefined, '/')
expect(result).toContain('src="/api/email/email1/attachment/abc.png"')
})
it('should combine baseUrl and basePath', () => {
const html = '<img src="cid:image123">'
const attachments = [{ contentId: 'image123', generatedFileName: 'abc.png' }]
const result = replaceCidReferences(html, 'email1', attachments, 'example.com', '/mail')
expect(result).toContain('src="//example.com/mail/api/email/email1/attachment/abc.png"')
})
it('should replace multiple cid references', () => {
const html = '<img src="cid:img1"><img src="cid:img2">'
const attachments = [