Skip to content

Commit

Permalink
parse._parsedParameters: do not use helpers.unescapedIndexOf()
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dilyanpalauzov authored and kewisch committed Apr 13, 2024
1 parent 722e144 commit 5f61c41
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/ical/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ parse._parseParameters = function(line, start, designSet) {
// then increment pos to find next ;

while ((pos !== false) &&
(pos = unescapedIndexOf(line, delim, pos + 1)) !== -1) {
(pos = line.indexOf(delim, pos + 1)) !== -1) {

name = line.slice(lastParam + 1, pos);
if (name.length == 0) {
Expand All @@ -370,12 +370,12 @@ parse._parseParameters = function(line, start, designSet) {
let nextChar = line[pos + 1];
if (nextChar === '"') {
valuePos = pos + 2;
pos = unescapedIndexOf(line, '"', valuePos);
pos = line.indexOf('"', valuePos);
if (multiValue && pos != -1) {
let extendedValue = true;
while (extendedValue) {
if (line[pos + 1] == multiValue && line[pos + 2] == '"') {
pos = unescapedIndexOf(line, '"', pos + 3);
pos = line.indexOf('"', pos + 3);
} else {
extendedValue = false;
}
Expand All @@ -387,8 +387,8 @@ parse._parseParameters = function(line, start, designSet) {
);
}
value = line.slice(valuePos, pos);
lastParam = unescapedIndexOf(line, PARAM_DELIMITER, pos);
let propValuePos = unescapedIndexOf(line, VALUE_DELIMITER, pos);
lastParam = line.indexOf(PARAM_DELIMITER, pos);
let propValuePos = line.indexOf(VALUE_DELIMITER, pos);
// if either no next parameter or delimeter in property value, let's stop here
if (lastParam === -1 || (propValuePos !== -1 && lastParam > propValuePos)) {
pos = false;
Expand All @@ -397,8 +397,8 @@ parse._parseParameters = function(line, start, designSet) {
valuePos = pos + 1;

// move to next ";"
let nextPos = unescapedIndexOf(line, PARAM_DELIMITER, valuePos);
let propValuePos = unescapedIndexOf(line, VALUE_DELIMITER, valuePos);
let nextPos = line.indexOf(PARAM_DELIMITER, valuePos);
let 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;
Expand Down
2 changes: 2 additions & 0 deletions test/parser/property_params.ics
Original file line number Diff line number Diff line change
Expand Up @@ -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:[email protected]";PAR
TSTAT=ACCEPTED;RSVP=TRUE:mailto:[email protected]
ATTENDEE;CN=X\:mailto:[email protected]
ATTENDEE;CN="Y\":mailto:[email protected]
X-FOO;PARAM1=VAL1:FOO;BAR
X-FOO2;PARAM1=VAL1;PARAM2=VAL2:FOO;BAR
X-BAR;PARAM1="VAL1:FOO":BAZ;BAR
Expand Down
16 changes: 16 additions & 0 deletions test/parser/property_params.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,22 @@
"cal-address",
"mailto:[email protected]"
],
[
"attendee",
{
"cn": "X\\"
},
"cal-address",
"mailto:[email protected]"
],
[
"attendee",
{
"cn": "Y\\"
},
"cal-address",
"mailto:[email protected]"
],
[
"x-foo",
{
Expand Down

0 comments on commit 5f61c41

Please sign in to comment.