From cdb58689699992b54c7332643051aaaee32450ff 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, 13 Sep 2022 22:39:19 +0300 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. https://github.com/kewisch/ical.js/pull/535 --- lib/ical/stringify.js | 15 +++++++-------- test/stringify_test.js | 7 +++++++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/ical/stringify.js b/lib/ical/stringify.js index f05cedc8..9007bc34 100644 --- a/lib/ical/stringify.js +++ b/lib/ical/stringify.js @@ -143,7 +143,7 @@ ICAL.stringify = (function() { line += ';' + paramName.toUpperCase(); - line += '=' + stringify.propertyValue(value); + line += '=' + stringify.propertyParameterValue(value); } } @@ -214,22 +214,21 @@ ICAL.stringify = (function() { }; /** - * Handles escaping of property values that may contain: + * Handles escaping of property parameter values that may contain: * * COLON (:), SEMICOLON (;), or COMMA (,) * * If any of the above are present the result is wrapped * in double quotes. * - * @function ICAL.stringify.propertyValue + * @function ICAL.stringify.propertyParameterValue * @param {String} value Raw property value * @return {String} Given or escaped value when needed */ - stringify.propertyValue = function(value) { - - if ((helpers.unescapedIndexOf(value, ',') === -1) && - (helpers.unescapedIndexOf(value, ':') === -1) && - (helpers.unescapedIndexOf(value, ';') === -1)) { + stringify.propertyParameterValue = function(value) { + if ((value.indexOf(',') === -1) && + (value.indexOf(':') === -1) && + (value.indexOf(';') === -1)) { return value; } diff --git a/test/stringify_test.js b/test/stringify_test.js index 7ef61703..32cd11b4 100644 --- a/test/stringify_test.js +++ b/test/stringify_test.js @@ -87,6 +87,13 @@ suite('ICAL.stringify', function() { delete ICAL.design.defaultSet.property.custom; }); + test('stringify property value containing "escaped" ; , :', function() { + var 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() { var subject = new ICAL.Property('attendee'); var input = "caret ^ dquote \" newline \n end";