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

kewisch#536
  • Loading branch information
dilyanpalauzov committed Sep 18, 2022
1 parent 0fe55fd commit d0d5391
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/ical/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
Expand All @@ -392,16 +392,16 @@ 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;
}
} else {
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;
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 @@ -10,6 +10,8 @@ ATTENDEE;DELEGATED-TO="mailto:foo7@bar";CN="Foo; Bar":mailto:foo6@bar
ATTENDEE;CN="^^Ж 4 <>\'^'^n:":mailto:foo9@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 @@ -77,6 +77,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 d0d5391

Please sign in to comment.