2018-05-09 02:07:01 +00:00
|
|
|
'use strict';
|
|
|
|
|
2018-05-13 20:40:34 +00:00
|
|
|
// FIXME - process also urlencoded strings - this is for the mosaico/img/template, which passes the file in src parameter
|
|
|
|
|
|
|
|
function base(text, trustedBaseUrl, sandboxBaseUrl) {
|
|
|
|
if (trustedBaseUrl.endsWith('/')) {
|
|
|
|
trustedBaseUrl = trustedBaseUrl.substring(0, trustedBaseUrl.length - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sandboxBaseUrl.endsWith('/')) {
|
|
|
|
sandboxBaseUrl = sandboxBaseUrl.substring(0, sandboxBaseUrl.length - 1);
|
2018-05-09 02:07:01 +00:00
|
|
|
}
|
|
|
|
|
2018-08-03 11:35:55 +00:00
|
|
|
text = text.split('[URL_BASE]').join(trustedBaseUrl);
|
|
|
|
text = text.split('[SANDBOX_URL_BASE]').join(sandboxBaseUrl);
|
|
|
|
text = text.split('[ENCODED_URL_BASE]').join(encodeURIComponent(trustedBaseUrl));
|
|
|
|
text = text.split('[ENCODED_SANDBOX_URL_BASE]').join(encodeURIComponent(sandboxBaseUrl));
|
|
|
|
|
|
|
|
return text;
|
2018-05-09 02:07:01 +00:00
|
|
|
}
|
|
|
|
|
2018-05-13 20:40:34 +00:00
|
|
|
function unbase(text, trustedBaseUrl, sandboxBaseUrl, treatSandboxAsTrusted = false) {
|
|
|
|
if (trustedBaseUrl.endsWith('/')) {
|
|
|
|
trustedBaseUrl = trustedBaseUrl.substring(0, trustedBaseUrl.length - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sandboxBaseUrl.endsWith('/')) {
|
|
|
|
sandboxBaseUrl = sandboxBaseUrl.substring(0, sandboxBaseUrl.length - 1);
|
2018-05-09 02:07:01 +00:00
|
|
|
}
|
|
|
|
|
2018-08-03 11:35:55 +00:00
|
|
|
text = text.split(trustedBaseUrl).join('[URL_BASE]');
|
|
|
|
text = text.split(sandboxBaseUrl).join(treatSandboxAsTrusted ? '[URL_BASE]' : '[SANDBOX_URL_BASE]');
|
|
|
|
text = text.split(encodeURIComponent(trustedBaseUrl)).join('[ENCODED_URL_BASE]');
|
|
|
|
text = text.split(encodeURIComponent(sandboxBaseUrl)).join(treatSandboxAsTrusted ? '[ENCODED_URL_BASE]' : '[ENCODED_SANDBOX_URL_BASE]');
|
|
|
|
|
|
|
|
return text;
|
2018-05-09 02:07:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
base,
|
|
|
|
unbase
|
|
|
|
};
|