From aafdcb79ac5148755cd707bec9b3e53c796648a5 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 17:51:38 +0300 Subject: [PATCH] parse._parsedParameters: do not use helpers.unescapedIndexOf() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit iCalendar and vCard parameters do not use \ as escape character in the property parameter values, hence cn="\"X" is not a quote X, but invalid. The proper escape character is ^ per RFC 6868. This change replaces helpers.unescapedIndexOf(x,…) with x.indexOf(…) in order not to count \ as escape character. --- lib/ical/parse.js | 12 ++++++------ test/parser/property_params.ics | 2 ++ test/parser/property_params.json | 16 ++++++++++++++++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/lib/ical/parse.js b/lib/ical/parse.js index 8d40636b..be894aa6 100644 --- a/lib/ical/parse.js +++ b/lib/ical/parse.js @@ -349,7 +349,7 @@ ICAL.parse = (function() { // then increment pos to find next ; while ((pos !== false) && - (pos = helpers.unescapedIndexOf(line, delim, pos + 1)) !== -1) { + (pos = line.indexOf(delim, pos + 1)) !== -1) { name = line.substr(lastParam + 1, pos - lastParam - 1); if (name.length == 0) { @@ -375,12 +375,12 @@ ICAL.parse = (function() { var nextChar = line[pos + 1]; if (nextChar === '"') { valuePos = pos + 2; - pos = helpers.unescapedIndexOf(line, '"', valuePos); + pos = line.indexOf('"', valuePos); if (multiValue && pos != -1) { var extendedValue = true; while (extendedValue) { if (line[pos + 1] == multiValue && line[pos + 2] == '"') { - pos = helpers.unescapedIndexOf(line, '"', pos + 3); + pos = line.indexOf('"', pos + 3); } else { extendedValue = false; } @@ -392,7 +392,7 @@ ICAL.parse = (function() { ); } value = line.substr(valuePos, pos - valuePos); - lastParam = helpers.unescapedIndexOf(line, PARAM_DELIMITER, pos); + lastParam = line.indexOf(PARAM_DELIMITER, pos); if (lastParam === -1) { pos = false; } @@ -400,8 +400,8 @@ ICAL.parse = (function() { valuePos = pos + 1; // move to next ";" - var nextPos = helpers.unescapedIndexOf(line, PARAM_DELIMITER, valuePos); - var propValuePos = helpers.unescapedIndexOf(line, VALUE_DELIMITER, valuePos); + var nextPos = line.indexOf(PARAM_DELIMITER, valuePos); + var propValuePos = line.indexOf(VALUE_DELIMITER, valuePos); if (propValuePos !== -1 && nextPos > propValuePos) { // this is a delimiter in the property value, let's stop here nextPos = propValuePos; diff --git a/test/parser/property_params.ics b/test/parser/property_params.ics index 6fbc1094..522afdcb 100644 --- a/test/parser/property_params.ics +++ b/test/parser/property_params.ics @@ -9,6 +9,8 @@ ATTENDEE;DELEGATED-TO="mailto:foo7@bar";CN="Foo, Bar":mailto:foo5@bar ATTENDEE;DELEGATED-TO="mailto:foo7@bar";CN="Foo; Bar":mailto:foo6@bar ATTENDEE;ROLE="REQ-PARTICIPANT;foo";DELEGATED-FROM="mailto:bar@baz.com";PAR TSTAT=ACCEPTED;RSVP=TRUE:mailto:foo@bar.com +ATTENDEE;CN=X\:mailto:x@example.org +ATTENDEE;CN="Y\":mailto:y@example.org X-FOO;PARAM1=VAL1:FOO;BAR X-FOO2;PARAM1=VAL1;PARAM2=VAL2:FOO;BAR X-BAR;PARAM1="VAL1:FOO":BAZ;BAR diff --git a/test/parser/property_params.json b/test/parser/property_params.json index 65ef665d..1ce9abeb 100644 --- a/test/parser/property_params.json +++ b/test/parser/property_params.json @@ -69,6 +69,22 @@ "cal-address", "mailto:foo@bar.com" ], + [ + "attendee", + { + "cn": "X\\" + }, + "cal-address", + "mailto:x@example.org" + ], + [ + "attendee", + { + "cn": "Y\\" + }, + "cal-address", + "mailto:y@example.org" + ], [ "x-foo", {