jens-maus / node-ical

NodeJS class for parsing iCalendar/ICS files
Apache License 2.0
118 stars 50 forks source link

parseICS fails if timezone id is a number #311

Closed antislash21 closed 6 months ago

antislash21 commented 6 months ago

I try to import an ics file (Thunderbird calendar export) with sync.parseICS function and get the following error:

Mon agenda.txt

TypeError: dt.tz.replace is not a function
addTZ /node_modules/node-ical/ical.js:105
dateParameter /node_modules/node-ical/ical.js:300
DTSTART /node_modules/node-ical/ical.js:650
handleObject /node_modules/node-ical/ical.js:674
parseLines /node_modules/node-ical/ical.js:726
parseICS /node_modules/node-ical/ical.js:762
parseICS /node_modules/node-ical/node-ical.js:206
onload /imports/ui/components/system/Calendar/utils.js:218
utils.js:147:14

after adding some console.log in ical.js, it seems that the problem comes from the fact that i have "TZID: 1", which makes the timezone id interpreted as a number.

The following code fails in ical.js (line 94 in function addTZ) :

    if (dt.tz !== undefined) {
      // Remove surrounding quotes if found at the beginning and at the end of the string
      // (Occurs when parsing Microsoft Exchange events containing TZID with Windows standard format instead IANA)
      dt.tz = dt.tz.replace(/^"(.*)"$/, '$1');
    }

If i change it to the following, parsing the file succeeds :

    if (dt.tz !== undefined && typeof(dt.tz) === "string") {
      // Remove surrounding quotes if found at the beginning and at the end of the string
      // (Occurs when parsing Microsoft Exchange events containing TZID with Windows standard format instead IANA)
      dt.tz = dt.tz.replace(/^"(.*)"$/, '$1');
    }

Thanks for your time, regards