Skip to content

Commit

Permalink
stringify: do not use unescapedIndexOf in property parameters
Browse files Browse the repository at this point in the history
… as \ is no escape character there.  When the propery parameter
contains :, then it must be quoted, the colon cannot be escaped.

As the function stringify.propertyValue in fact stringifies
property parameter values, it is renamed accordingly.

kewisch#535
  • Loading branch information
dilyanpalauzov committed Sep 18, 2022
1 parent d0d5391 commit cdb5868
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
15 changes: 7 additions & 8 deletions lib/ical/stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ ICAL.stringify = (function() {


line += ';' + paramName.toUpperCase();
line += '=' + stringify.propertyValue(value);
line += '=' + stringify.propertyParameterValue(value);
}
}

Expand Down Expand Up @@ -214,22 +214,21 @@ ICAL.stringify = (function() {
};

/**
* Handles escaping of property values that may contain:
* Handles escaping of property parameter values that may contain:
*
* COLON (:), SEMICOLON (;), or COMMA (,)
*
* If any of the above are present the result is wrapped
* in double quotes.
*
* @function ICAL.stringify.propertyValue
* @function ICAL.stringify.propertyParameterValue
* @param {String} value Raw property value
* @return {String} Given or escaped value when needed
*/
stringify.propertyValue = function(value) {

if ((helpers.unescapedIndexOf(value, ',') === -1) &&
(helpers.unescapedIndexOf(value, ':') === -1) &&
(helpers.unescapedIndexOf(value, ';') === -1)) {
stringify.propertyParameterValue = function(value) {
if ((value.indexOf(',') === -1) &&
(value.indexOf(':') === -1) &&
(value.indexOf(';') === -1)) {

return value;
}
Expand Down
7 changes: 7 additions & 0 deletions test/stringify_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ suite('ICAL.stringify', function() {
delete ICAL.design.defaultSet.property.custom;
});

test('stringify property value containing "escaped" ; , :', function() {
var subject = new ICAL.Property('attendee');
subject.setParameter('cn', 'X\\:');
subject.setValue('mailto:id');
assert.equal(subject.toICALString(), 'ATTENDEE;CN="X\\:":mailto:id');
});

test('rfc6868 roundtrip', function() {
var subject = new ICAL.Property('attendee');
var input = "caret ^ dquote \" newline \n end";
Expand Down

0 comments on commit cdb5868

Please sign in to comment.