mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
The HTML-formatted notification email built its body from the same plain-text line used for the non-HTML email, so the card/board URL sat as bare text instead of a clickable link. buildHtmlNotificationLine() now builds the HTML body directly, escaping the actor name/description exactly as before and wrapping the URL in an escaped <a href>. The plain-text email is unchanged. Thanks to papimla and xet7 ! Closes #3118,
36 lines
1.3 KiB
JavaScript
36 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
function escapeEmailHtml(value) {
|
|
return String(value ?? '')
|
|
.replaceAll('&', '&')
|
|
.replaceAll('<', '<')
|
|
.replaceAll('>', '>')
|
|
.replaceAll('"', '"')
|
|
.replaceAll("'", ''');
|
|
}
|
|
|
|
function safeEmailSubject(value) {
|
|
return String(value ?? '').replace(/[\r\n]+/g, ' ').trim();
|
|
}
|
|
|
|
// #3118: an HTML-formatted notification email must render the card/board URL
|
|
// as a real clickable <a href> link, not as plain text that merely looks like
|
|
// one. Every dynamic piece is escaped BEFORE it is placed into the markup, so
|
|
// the subject/actor name/description can never inject markup of their own;
|
|
// only the wrapping <a href="..."> tag itself is real HTML. Pulled out as a
|
|
// pure function (no Meteor/TAPi18n dependency) so it can be unit tested.
|
|
function buildHtmlNotificationLine({ existing, subject, actorName, descriptionText, url }) {
|
|
const htmlHead = existing
|
|
? `<br/>\n${escapeEmailHtml(subject)}<br/>\n`
|
|
: '';
|
|
const safeUrl = url || '';
|
|
const link = safeUrl
|
|
? `<a href="${escapeEmailHtml(safeUrl)}">${escapeEmailHtml(safeUrl)}</a>`
|
|
: '';
|
|
return `${htmlHead}${escapeEmailHtml(actorName || '')} ${escapeEmailHtml(
|
|
descriptionText || '',
|
|
)}${link ? `<br/>\n${link}` : ''}`;
|
|
}
|
|
|
|
module.exports = { escapeEmailHtml, safeEmailSubject, buildHtmlNotificationLine };
|