From a191c500fde5084c484aeade0466f759ea00b8e9 Mon Sep 17 00:00:00 2001 From: Claas Augner Date: Fri, 5 Apr 2019 18:42:16 +0200 Subject: [PATCH] fix(parser): support multiple vCard TYPE parameter Fixes #343. --- lib/ical/parse.js | 17 +++++++++++++++-- test/parse_test.js | 24 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/lib/ical/parse.js b/lib/ical/parse.js index d9807bd5..6137fc74 100644 --- a/lib/ical/parse.js +++ b/lib/ical/parse.js @@ -412,9 +412,22 @@ ICAL.parse = (function() { value = parser._rfc6868Escape(value); if (multiValue) { var delimiter = mvdelim || multiValue; - result[lcname] = parser._parseMultiValue(value, delimiter, type, [], null, designSet); + value = parser._parseMultiValue(value, delimiter, type, [], null, designSet); } else { - result[lcname] = parser._parseValue(value, type, designSet); + value = parser._parseValue(value, type, designSet); + } + + if (multiValue && (lcname in result)) { + if (Array.isArray(result[lcname])) { + result[lcname].push(value); + } else { + result[lcname] = [ + result[lcname], + value + ]; + } + } else { + result[lcname] = value; } } return [result, value, valuePos]; diff --git a/test/parse_test.js b/test/parse_test.js index 4d375869..111a1581 100644 --- a/test/parse_test.js +++ b/test/parse_test.js @@ -186,6 +186,30 @@ suite('parserv2', function() { expected ); }); + + test('with multiple vCard TYPE parameters', function() { + var input = ';TYPE=work;TYPE=voice'; + var expected = { + 'type': ['work', 'voice'] + }; + + assert.deepEqual( + subject._parseParameters(input, 0, ICAL.design.components.vcard)[0], + expected + ); + }); + + test('with multiple iCalendar MEMBER parameters', function() { + var input = ';MEMBER="urn:one","urn:two";MEMBER="urn:three"'; + var expected = { + 'member': ['urn:one', 'urn:two', 'urn:three'] + }; + + assert.deepEqual( + subject._parseParameters(input, 0, ICAL.design.components.vevent)[0], + expected + ); + }); }); test('#_parseMultiValue', function() {