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.
  • Loading branch information
dilyanpalauzov authored and kewisch committed Apr 13, 2024
1 parent 9e96f20 commit 722e144
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/ical/stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Portions Copyright (C) Philipp Kewisch */

import design from "./design.js";
import { foldline, unescapedIndexOf } from "./helpers.js";
import { foldline } from "./helpers.js";

const LINE_ENDING = '\r\n';
const DEFAULT_VALUE_TYPE = 'unknown';
Expand Down Expand Up @@ -131,7 +131,6 @@ stringify.property = function(property, designSet, noFold) {
value = stringify.paramPropertyValue(value);
}


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

Expand Down Expand Up @@ -216,9 +215,9 @@ stringify.property = function(property, designSet, noFold) {
*/
stringify.paramPropertyValue = function(value, force) {
if (!force &&
(unescapedIndexOf(value, ',') === -1) &&
(unescapedIndexOf(value, ':') === -1) &&
(unescapedIndexOf(value, ';') === -1)) {
(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 @@ -113,6 +113,13 @@ suite('ICAL.stringify', function() {
delete ICAL.design.defaultSet.param.type;
});

test('stringify property value containing "escaped" semicolons, commas, colons', function() {
let 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() {
let subject = new ICAL.Property('attendee');
let input = "caret ^ dquote \" newline \n end";
Expand Down

0 comments on commit 722e144

Please sign in to comment.