From 00c1323f07325abae0fa0e6bd1406da1b8257eb3 Mon Sep 17 00:00:00 2001 From: Fabrice Mouhartem Date: Fri, 20 Oct 2023 14:12:53 +0200 Subject: [PATCH] #1171: ICS line wrapping for descriptions in export Descriptions can be long and RFC5545 states that a line shouldn't be more than 75 bytes long. --- www/calendar/export.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/www/calendar/export.js b/www/calendar/export.js index ad5f23fa3..de61be5e6 100644 --- a/www/calendar/export.js +++ b/www/calendar/export.js @@ -104,8 +104,13 @@ define([ var end = dt.end; var rrule = getRRule(data); - var escapeValue = function(str) { - return str.replace(/\n/g, ["\\n"]); + var formatDescription = function(str) { + var result = str.replace(/\n/g, ["\\n"]); + // XXX Should use ical.js helper foldline instead ↓ + // XXX https://kewisch.github.io/ical.js/api/ICAL.module_helpers.html#.foldline + // In RFC5545: https://www.rfc-editor.org/rfc/rfc5545#section-3.1 + result = result.replace(/([^\n]{1,74})/g, '$1\n '); + return result; }; Array.prototype.push.apply(arr, [ @@ -118,7 +123,7 @@ define([ rrule, 'SUMMARY:'+ data.title, 'LOCATION:'+ data.location, - 'DESCRIPTION:' + escapeValue(data.body), + 'DESCRIPTION:' + formatDescription(data.body), ].filter(Boolean)); if (Array.isArray(data.reminders)) {