Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle parameter values with multiple entries #702

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions lib/ical/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,21 @@ parse._handleContentLine = function(line, state) {
if (paramPos !== -1) {
name = line.slice(0, Math.max(0, paramPos)).toLowerCase();
parsedParams = parse._parseParameters(line.slice(Math.max(0, paramPos)), 0, state.designSet);
console.log(parsedParams);
if (parsedParams[2] == -1) {
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) => {
onny marked this conversation as resolved.
Show resolved Hide resolved
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 +320,13 @@ parse._parseValue = function(value, type, designSet, structuredValue) {
*
* @function ICAL.parse._parseParameters
* @private
* @param {String} line A single unfolded line
* @param {Numeric} 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 {Numeric} start Position to start looking for properties
* @param {Object} designSet The design data to use for this property
* @return {[Object, Number, Number]} Array containing:
* - 1. Key/value pairs of parsed parameters,
* - 2. Parsed value,
* - 3. 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() {
onny marked this conversation as resolved.
Show resolved Hide resolved
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);
});
});
24 changes: 24 additions & 0 deletions test/parse_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,30 @@ suite('parserv2', function() {
);
});

test('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);
});

test('with quoted value', function() {
let input = ';FMTTYPE="text/html":Here is HTML with signs like =;';
let expected = {
Expand Down