'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 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 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
? `
\n${escapeEmailHtml(subject)}
\n`
: '';
const safeUrl = url || '';
const link = safeUrl
? `${escapeEmailHtml(safeUrl)}`
: '';
return `${htmlHead}${escapeEmailHtml(actorName || '')} ${escapeEmailHtml(
descriptionText || '',
)}${link ? `
\n${link}` : ''}`;
}
module.exports = { escapeEmailHtml, safeEmailSubject, buildHtmlNotificationLine };