From 843c7b8d353c0512c1e59e4b955ea6af4e150f4b Mon Sep 17 00:00:00 2001 From: Haja Date: Thu, 24 Apr 2025 16:19:38 +0300 Subject: [PATCH] [Calendar] Enlever les logs --- calendar/src/models/calendarObject.js | 22 +++++++++++++++++++++- calendar/src/store/calendarObjects.js | 14 ++++++++++---- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/calendar/src/models/calendarObject.js b/calendar/src/models/calendarObject.js index 4e80758..33a9a80 100644 --- a/calendar/src/models/calendarObject.js +++ b/calendar/src/models/calendarObject.js @@ -141,11 +141,31 @@ const setCustomKeyValuesArrayToIcsAndReturnIcs = (ics, keyValueArray) => { return ics; } +const escapeICSField = (value) => { + return value + .replace(/\\/g, '\\\\') + .replace(/\n/g, '\\n') + .replace(/,/g, '\\,') + .replace(/;/g, '\\;'); +} + +const foldICSLines = (line) => { + const folded = []; + while (line.length > 75) { + folded.push(line.slice(0, 75)); + line = ' ' + line.slice(75); // continuation line starts with a space + } + folded.push(line); + return folded.join('\r\n'); +} + export { getDefaultCalendarObjectObject, mapCDavObjectToCalendarObject, mapCalendarJsToCalendarObject, setCustomKeyValuesArrayToIcsAndReturnIcs, getKeyValueIcsProperty, - setCustomKeyValueToIcsAndReturnIcs + setCustomKeyValueToIcsAndReturnIcs, + escapeICSField, + foldICSLines, } diff --git a/calendar/src/store/calendarObjects.js b/calendar/src/store/calendarObjects.js index 6da16b8..c2ec0de 100644 --- a/calendar/src/store/calendarObjects.js +++ b/calendar/src/store/calendarObjects.js @@ -24,7 +24,7 @@ * */ import Vue from 'vue' -import { mapCalendarJsToCalendarObject, setClientValueToIcsAndReturnIcs, setCustomKeyValuesArrayToIcsAndReturnIcs } from '../models/calendarObject.js' +import { mapCalendarJsToCalendarObject, setClientValueToIcsAndReturnIcs, setCustomKeyValuesArrayToIcsAndReturnIcs, foldICSLines, escapeICSField } from '../models/calendarObject.js' import logger from '../utils/logger.js' import { createEvent, @@ -227,6 +227,7 @@ const actions = { let eventComponent = calendarObject.calendarComponent.getFirstComponent('VEVENT'); if (calendarObject.existsOnServer) { let icsValue = calendarObject.calendarComponent.toICS(); + if(eventComponent != null){ if(eventComponent.client != null){ let newClientKeyValue = "CLIENT:"+eventComponent.client; @@ -246,14 +247,18 @@ const actions = { } } if(eventComponent.comment != null){ - let newCommentKeyValue = "COMMENT:"+eventComponent.comment; - let regex = /COMMENT:[^\s]+/; + const escapedComment = escapeICSField(eventComponent.comment) + const foldedComment = foldICSLines(escapedComment) + + let newCommentKeyValue = "COMMENT:"+foldedComment; + //let regex = /COMMENT:[^\s]+/; + let regex = /^COMMENT:.*$/m; if(regex.test(icsValue)){ icsValue = icsValue.replace(regex, newCommentKeyValue); } else{ const customKeyValue = { - "COMMENT": eventComponent.comment + "COMMENT": foldedComment }; icsValue = setCustomKeyValuesArrayToIcsAndReturnIcs(icsValue,customKeyValue); } @@ -304,6 +309,7 @@ const actions = { } } } + calendarObject.dav.data = icsValue; await calendarObject.dav.update() context.commit('addCalendarObjectIdToAllTimeRangesOfCalendar', {