From e6b653124853ce37eeb329a596d6b3994101663a Mon Sep 17 00:00:00 2001 From: djmaze Date: Tue, 7 Dec 2021 12:40:55 +0100 Subject: [PATCH] Move b64EncodeJSON to Utils --- dev/Common/Utils.js | 9 +++++++++ dev/Model/SieveScript.js | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/dev/Common/Utils.js b/dev/Common/Utils.js index f1eb99dba..ed395fbd7 100644 --- a/dev/Common/Utils.js +++ b/dev/Common/Utils.js @@ -49,6 +49,15 @@ export const } }, + // unescape(encodeURIComponent()) makes the UTF-16 DOMString to an UTF-8 string + b64EncodeJSON = data => btoa(unescape(encodeURIComponent(JSON.stringify(data)))), +/* // Without deprecated 'unescape': + b64EncodeJSON = data => btoa(encodeURIComponent(JSON.stringify(data)).replace( + /%([0-9A-F]{2})/g, (match, p1) => String.fromCharCode('0x' + p1) + )), +*/ + b64EncodeJSONSafe = data => b64EncodeJSON(data).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, ''), + settingsSaveHelperSimpleFunction = (koTrigger, context) => iError => { koTrigger.call(context, iError ? SaveSettingsStep.FalseResult : SaveSettingsStep.TrueResult); diff --git a/dev/Model/SieveScript.js b/dev/Model/SieveScript.js index 18b4eb02c..620abfe86 100644 --- a/dev/Model/SieveScript.js +++ b/dev/Model/SieveScript.js @@ -2,7 +2,7 @@ import ko from 'ko'; import { AbstractModel } from 'Knoin/AbstractModel'; import { FilterModel } from 'Model/Filter'; -import { arrayLength, pString } from 'Common/Utils'; +import { arrayLength, pString, b64EncodeJSON } from 'Common/Utils'; const SIEVE_FILE_NAME = 'rainloop.user'; @@ -215,7 +215,7 @@ function filtersToSieveScript(filters) '/*', 'BEGIN:FILTER:' + filter.id, 'BEGIN:HEADER', - btoa(unescape(encodeURIComponent(JSON.stringify(filter.toJson())))).match(split).join(eol) + 'END:HEADER', + b64EncodeJSON(filter.toJson()).match(split).join(eol) + 'END:HEADER', '*/', filter.enabled() ? '' : '/* @Filter is disabled ', filterToString(filter, require),