Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad code in the getTimeZone and dateParameter function - crashing #319

Open
sujal opened this issue May 7, 2024 · 0 comments
Open

Bad code in the getTimeZone and dateParameter function - crashing #319

sujal opened this issue May 7, 2024 · 0 comments

Comments

@sujal
Copy link
Contributor

sujal commented May 7, 2024

I have a user-submitted ical feed with a bad timezone:

DTSTART;TZID="(UTC-05:00) Eastern Time (US & C":20240429T170000

First, before we get into what to do about it, that DTSTART is causing my service to crash because of this code (line 151):

  // Watch out for offset timezones
  // If the conversion above didn't find any matching IANA tz
  // And offset is still present
  if (tz && tz.startsWith('(')) {
    // Extract just the offset
    const regex = /[+|-]\d*:\d*/;
    tz = null;
    found = tz.match(regex);
  }

Note that it sets the tz variable to null right before trying to access it. That's just broken, those two operations need to be swapped. (You can see this in a separate block around line 261 that does the same logic)

So, that is a small change, but I don't understand what this code is trying to do. In that case, it's inside getTimeZone which looks like it otherwise is supposed to return an IANA time zone string.

Which brings me to the second item to note: the match call returns an array, not a string. Later code doesn't expect that to be the case, throws errors if I fix the above issue.

I don't know how to map an offset to a IANA timezone without knowing what time zones the user cares about, as I don't know if they are looking for a zone with that offset that supports DST or not. In this case, the rest of the broken TZID string tells me as a human that this should be eastern time in the US, but not sure how to write a general solution for that.

Can someone explain what this block of code was trying to do? I have a fix locally, with a test, but the time is getting set to UTC for that event.

It prevents the crash, though, so we may have to roll with it until we can understand what might be a better fix...

Appreciate any insight, happy to write the code to fix if there's a recommendation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant