Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release production (encode URL) #753

Merged
merged 3 commits into from
Dec 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 7 additions & 51 deletions packages/server/utils/process-mosaico-html-render.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,9 @@ function secureHtml(html) {
});
}

// selligent tags between “href” or “src” are encoded at the export
// • we need to reverse the operation to keep them OK
// use another decodeUriComponent instead of native
// • native had problems de-encoding selligent tags
// due to date format %d%m%Y
// • (FORMATDATETIME(GETDATE(),%20%27%d%m%Y%27))
const selligentTagRegexp = /~(.+?)~/g;
const np6TagRegexp = /{{(.+?)}}/g;
const actitoTagRegexp = /\${(.+?)\}/g;
const adobeTagRegexp = /<%(.+?)%>/g;
const dscTagRegexp = /<#list(.+?)<\/#list>/g;
// We don't want to manage any special format inside href now. We let the reponsability to users to decode
// themselves links in href (but only for href values) that's why we use this regex below
const globalRegexp = /href="(.+?)"/g;

const decodeTag = (match, tag, fun = (value) => value) => {
let decodedTag = htmlEntities.decode(tag);
Expand All @@ -53,54 +45,18 @@ const decodeTag = (match, tag, fun = (value) => value) => {
return decodedTag;
};

function decodeSelligentTags(html) {
function decodeGlobalTags(html) {
return html.replace(
selligentTagRegexp,
(match, tag) => `~${decodeTag(match, tag)}~`
);
}

function decodeNp6Tags(html) {
return html.replace(
np6TagRegexp,
(match, tag) => `{{${decodeTag(match, tag)}}}`
);
}

function decodeActitoTags(html) {
html = html.replace(
actitoTagRegexp,
(match, tag) => `\${${decodeTag(match, tag)}}`
);
return html;
}

function decodeAdobeTags(html) {
return html.replace(
adobeTagRegexp,
(match, tag) =>
`<%${decodeTag(match, tag, (tagSelection) =>
tagSelection.replace(/\+/g, '%2B')
)}%>`
);
}

function decodeDscTags(html) {
return html.replace(
dscTagRegexp,
(match, tag) => `<#list${decodeTag(match, tag)}</#list>`
globalRegexp,
(match, tag) => `href="${decodeTag(match, tag)}"`
);
}

const basicHtmlProcessing = _.flow(
removeTinyMceExtraBrTag,
replaceTabs,
secureHtml,
decodeSelligentTags,
decodeNp6Tags,
decodeActitoTags,
decodeAdobeTags,
decodeDscTags
decodeGlobalTags
);

module.exports = basicHtmlProcessing;
Loading