Skip to content

Commit

Permalink
Handle parameter values with multiple entries
Browse files Browse the repository at this point in the history
  • Loading branch information
onny authored and kewisch committed Jan 5, 2025
1 parent 015f08c commit 486a219
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 32 deletions.
20 changes: 15 additions & 5 deletions lib/ical/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,16 @@ parse._handleContentLine = function(line, state) {
throw new ParserError("Invalid parameters in '" + line + "'");
}
params = parsedParams[0];
lastParamIndex = parsedParams[1].length + parsedParams[2] + paramPos;
// Handle parameter values with multiple entries
let parsedParamLength;
if (typeof parsedParams[1] === 'string') {
parsedParamLength = parsedParams[1].length;
} else {
parsedParamLength = parsedParams[1].reduce((accumulator, currentValue) => {
return accumulator + currentValue.length;
}, 0);
}
lastParamIndex = parsedParamLength + parsedParams[2] + paramPos;
if ((lastValuePos =
line.slice(Math.max(0, lastParamIndex)).indexOf(VALUE_DELIMITER)) !== -1) {
value = line.slice(Math.max(0, lastParamIndex + lastValuePos + 1));
Expand Down Expand Up @@ -310,10 +319,11 @@ parse._parseValue = function(value, type, designSet, structuredValue) {
*
* @function ICAL.parse._parseParameters
* @private
* @param {String} line A single unfolded line
* @param {Number} start Position to start looking for properties
* @param {Object} designSet The design data to use for this property
* @return {Object} key/value pairs
* @param {String} line A single unfolded line
* @param {Number} start Position to start looking for properties
* @param {Object} designSet The design data to use for this property
* @return {Array} Array containing key/valye pairs of parsed parameters, the
* parsed value, and the position of the last parameter found
*/
parse._parseParameters = function(line, start, designSet) {
let lastParam = start;
Expand Down
27 changes: 0 additions & 27 deletions test/failure_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,4 @@ suite('Known failures', function() {
assert.equal(subject.getParameter("cn"), "Z\\;");
assert.equal(subject.getFirstValue(), "mailto:[email protected]");
});

// Quoted multi-value parameters leak into the value
// Please see https://github.com/kewisch/ical.js/issues/634
testKnownFailure('with quoted multi-value parameter', function() {
let attendee = ICAL.Property.fromString(
'ATTENDEE;MEMBER=' +
'"mailto:mygroup@localhost",' +
'"mailto:mygroup2@localhost",' +
'"mailto:mygroup3@localhost":' +
'mailto:user2@localhost'
);

let expected = [
'attendee',
{
member: [
'mailto:mygroup@localhost',
'mailto:mygroup2@localhost',
'mailto:mygroup3@localhost'
]
},
'cal-address',
'mailto:user2@localhost'
];

assert.deepEqual(attendee.toJSON(), expected);
});
});

0 comments on commit 486a219

Please sign in to comment.