From 8b0f55932af94cf8352afd7269d25dee5939f8de Mon Sep 17 00:00:00 2001 From: Simon Berger Date: Mon, 19 Aug 2024 11:03:37 +0200 Subject: [PATCH] Fix double quote parsing error (#332) --- ical.js | 8 ++++++-- test/test.js | 16 ++++++++++++++++ test/test22.ics | 6 ++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 test/test22.ics diff --git a/ical.js b/ical.js index fb87f91..1e19bcc 100644 --- a/ical.js +++ b/ical.js @@ -17,7 +17,8 @@ const text = function (t = '') { .replace(/\\,/g, ',') .replace(/\\;/g, ';') .replace(/\\[nN]/g, '\n') - .replace(/\\\\/g, '\\'); + .replace(/\\\\/g, '\\') + .replace(/^"(.*)"$/, '$1'); }; const parseValue = function (value) { @@ -34,6 +35,9 @@ const parseValue = function (value) { return number; } + // Remove quotes if found + value = value.replace(/^"(.*)"$/, '$1'); + return value; }; @@ -698,7 +702,7 @@ module.exports = { } // Remove any double quotes in any tzid statement// except around (utc+hh:mm - if (l.indexOf('TZID=') && !l.includes('"(')) { + if (l.includes('TZID=') && !l.includes('"(')) { l = l.replace(/"/g, ''); } diff --git a/test/test.js b/test/test.js index 2dd83dc..6963f28 100644 --- a/test/test.js +++ b/test/test.js @@ -976,6 +976,22 @@ vows } } }, + 'with test22.ics (quoted parameter values)': { + topic() { + return ical.parseFile('./test/test22.ics'); + }, + 'grabbing VEVENT': { + topic(topic) { + return _.values(topic)[0]; + }, + 'it has the correct response comment'(event) { + // See: + assert.equal(event.attendee.params['X-RESPONSE-COMMENT'], 'Test link: https://example.com/test'); + assert.equal(event.attendee.params.CUTYPE, 'INDIVIDUAL'); + assert.equal(event.attendee.val, 'mailto:test@example.com'); + } + } + }, 'with test_with_tz_list.ics': { topic() { return ical.parseFile('./test/test_with_tz_list.ics'); diff --git a/test/test22.ics b/test/test22.ics new file mode 100644 index 0000000..1968f91 --- /dev/null +++ b/test/test22.ics @@ -0,0 +1,6 @@ +BEGIN:VCALENDAR +BEGIN:VEVENT +SUMMARY:Meeting +ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=ACCEPTED;X-NUM-GUESTS=0;X-RESPONSE-COMMENT="Test link: https://example.com/test":mailto:test@example.com +END:VEVENT +END:VCALENDAR