From 5696750c5c337d8b299b3ccce85dcd978b88a00d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B8=D0=BB=D1=8F=D0=BD=20=D0=9F=D0=B0=D0=BB=D0=B0?= =?UTF-8?q?=D1=83=D0=B7=D0=BE=D0=B2?= Date: Tue, 9 Apr 2024 18:35:09 +0000 Subject: [PATCH] stringify: do not use unescapedIndexOf in property parameters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … as \ is no escape character there. When the propery parameter contains :, then it must be quoted, the colon cannot be escaped. As the function stringify.propertyValue in fact stringifies property parameter values, it is renamed accordingly. --- lib/ical/stringify.js | 17 ++++++++--------- test/stringify_test.js | 7 +++++++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/ical/stringify.js b/lib/ical/stringify.js index f388cb2c..ea0f5f60 100644 --- a/lib/ical/stringify.js +++ b/lib/ical/stringify.js @@ -4,7 +4,7 @@ * Portions Copyright (C) Philipp Kewisch */ import design from "./design.js"; -import { foldline, unescapedIndexOf } from "./helpers.js"; +import { foldline } from "./helpers.js"; const LINE_ENDING = '\r\n'; const DEFAULT_VALUE_TYPE = 'unknown'; @@ -122,16 +122,15 @@ stringify.property = function(property, designSet, noFold) { if (multiValue && Array.isArray(value)) { value = value.map(function(val) { val = stringify._rfc6868Unescape(val); - val = stringify.paramPropertyValue(val, paramDesign.multiValueSeparateDQuote); + val = stringify.propertyParameterValue(val, paramDesign.multiValueSeparateDQuote); return val; }); value = stringify.multiValue(value, multiValue, "unknown", null, designSet); } else { value = stringify._rfc6868Unescape(value); - value = stringify.paramPropertyValue(value); + value = stringify.propertyParameterValue(value); } - line += ';' + paramName.toUpperCase() + '=' + value; } @@ -209,16 +208,16 @@ stringify.property = function(property, designSet, noFold) { * If any of the above are present the result is wrapped * in double quotes. * - * @function ICAL.stringify.paramPropertyValue + * @function ICAL.stringify.propertyParameterValue * @param {String} value Raw property value * @param {boolean} force If value should be escaped even when unnecessary * @return {String} Given or escaped value when needed */ -stringify.paramPropertyValue = function(value, force) { +stringify.propertyParameterValue = function(value, force) { if (!force && - (unescapedIndexOf(value, ',') === -1) && - (unescapedIndexOf(value, ':') === -1) && - (unescapedIndexOf(value, ';') === -1)) { + (value.indexOf(',') === -1) && + (value.indexOf(':') === -1) && + (value.indexOf(';') === -1)) { return value; } diff --git a/test/stringify_test.js b/test/stringify_test.js index 40337b84..1ffbf661 100644 --- a/test/stringify_test.js +++ b/test/stringify_test.js @@ -113,6 +113,13 @@ suite('ICAL.stringify', function() { delete ICAL.design.defaultSet.param.type; }); + test('stringify property value containing "escaped" ; , :', function() { + let subject = new ICAL.Property('attendee'); + subject.setParameter('cn', 'X\\:'); + subject.setValue('mailto:id'); + assert.equal(subject.toICALString(), 'ATTENDEE;CN="X\\:":mailto:id'); + }); + test('rfc6868 roundtrip', function() { let subject = new ICAL.Property('attendee'); let input = "caret ^ dquote \" newline \n end";