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.
  • Loading branch information
dilyanpalauzov committed Apr 9, 2024
1 parent 59245d9 commit 5696750
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
17 changes: 8 additions & 9 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 @@ -122,16 +122,15 @@ stringify.property = function(property, designSet, noFold) {
if (multiValue && Array.isArray(value)) {
value = value.map(function(val) {
val = stringify._rfc6868Unescape(val);
val = stringify.paramPropertyValue(val, paramDesign.multiValueSeparateDQuote);
val = stringify.propertyParameterValue(val, paramDesign.multiValueSeparateDQuote);
return val;
});
value = stringify.multiValue(value, multiValue, "unknown", null, designSet);
} else {
value = stringify._rfc6868Unescape(value);
value = stringify.paramPropertyValue(value);
value = stringify.propertyParameterValue(value);
}


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

Expand Down Expand Up @@ -209,16 +208,16 @@ stringify.property = function(property, designSet, noFold) {
* If any of the above are present the result is wrapped
* in double quotes.
*
* @function ICAL.stringify.paramPropertyValue
* @function ICAL.stringify.propertyParameterValue
* @param {String} value Raw property value
* @param {boolean} force If value should be escaped even when unnecessary
* @return {String} Given or escaped value when needed
*/
stringify.paramPropertyValue = function(value, force) {
stringify.propertyParameterValue = 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" ; , :', 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 5696750

Please sign in to comment.