Skip to content

Commit

Permalink
Quote (or don't quote) parameter property values individually before …
Browse files Browse the repository at this point in the history
…joining

Instead of adding quotes to the delimiting comma and around the outside, quote the individual members separately if necessary.
This prevents the whole string of multiple values being quoted because of the presence of a delimiting comma.

When quotes are required (multiValueSeparateDQuote is true) only URIs are valid, which will get quoted due to the colon.
When not required only specific strings (WORK, VOICE, PARCEL, etc.) are valid, none of which need quotes.
  • Loading branch information
darktrojan committed Nov 9, 2022
1 parent 3f0838c commit a550a9f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/ical/design.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ let commonValues = {

let icalParams = {
// Although the syntax is DQUOTE uri DQUOTE, I don't think we should
// enfoce anything aside from it being a valid content line.
// enforce anything aside from it being a valid content line.
//
// At least some params require - if multi values are used - DQUOTEs
// for each of its values - e.g. delegated-from="uri1","uri2"
Expand Down
13 changes: 5 additions & 8 deletions lib/ical/stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,16 @@ stringify.property = function(property, designSet, noFold) {
}
let multiValue = (paramName in designSet.param) && designSet.param[paramName].multiValue;
if (multiValue && Array.isArray(value)) {
if (designSet.param[paramName].multiValueSeparateDQuote) {
multiValue = '"' + multiValue + '"';
}
value = value.map(stringify._rfc6868Unescape);
value = value.map(stringify.paramPropertyValue);
value = stringify.multiValue(value, multiValue, "unknown", null, designSet);
} else {
value = stringify._rfc6868Unescape(value);
value = stringify.paramPropertyValue(value);
}


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

if (property.length === 3) {
Expand Down Expand Up @@ -206,12 +204,11 @@ stringify.property = function(property, designSet, noFold) {
* If any of the above are present the result is wrapped
* in double quotes.
*
* @function ICAL.stringify.propertyValue
* @function ICAL.stringify.paramPropertyValue
* @param {String} value Raw property value
* @return {String} Given or escaped value when needed
*/
stringify.propertyValue = function(value) {

stringify.paramPropertyValue = function(value) {
if ((unescapedIndexOf(value, ',') === -1) &&
(unescapedIndexOf(value, ':') === -1) &&
(unescapedIndexOf(value, ';') === -1)) {
Expand Down
30 changes: 30 additions & 0 deletions test/stringify_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,35 @@ suite('ICAL.stringify', function() {

assert.equal(ICAL.stringify.component(subject), expected);
});

test('multiple types unquoted', function() {
let subject = [
"vcard",
[
[
"adr",
{
type: ["dom", "home", "postal", "parcel"]
},
"text",
["", "", "123 Main Street", "Any Town", "CA", "91921-1234"]
],
[
"tel",
{
type: ["home", "voice", "x-a", "x-b,x-c"]
},
"phone-number",
"1234567"
]
]
];
let expected =
"BEGIN:VCARD\r\n" +
"ADR;TYPE=dom,home,postal,parcel:;;123 Main Street;Any Town;CA;91921-1234\r\n" +
"TEL;TYPE=home,voice,x-a,\"x-b,x-c\":1234567\r\n" +
"END:VCARD";
assert.equal(ICAL.stringify.component(subject), expected);
});
});
});

0 comments on commit a550a9f

Please sign in to comment.