From c38ddae1381c8f84dff6843868903dbfc42ea4a0 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. --- lib/ical/stringify.js | 9 ++++----- test/stringify_test.js | 7 +++++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/ical/stringify.js b/lib/ical/stringify.js index f388cb2c..12415968 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'; @@ -131,7 +131,6 @@ stringify.property = function(property, designSet, noFold) { value = stringify.paramPropertyValue(value); } - line += ';' + paramName.toUpperCase() + '=' + value; } @@ -216,9 +215,9 @@ stringify.property = function(property, designSet, noFold) { */ stringify.paramPropertyValue = 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..48a6714f 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" semicolons, commas, colons', 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";