Repository navigation
fix: tolerate empty BYMONTHDAY values #3303
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,21 @@ import { | |
| mapRecurrenceRuleValueToRecurrenceRuleObject, | ||
| } from './recurrenceRule.js' | ||
|
|
||
| /** | ||
| * Removes empty values from BYMONTHDAY lists before parsing. Some CalDAV | ||
| * clients send values such as `BYMONTHDAY=,24`, which ical.js rejects. | ||
| * @param {string} vcalendar The vCalendar data | ||
| * @return {string} | ||
| */ | ||
| function normalizeEmptyByMonthDayValues(vcalendar) { | ||
| return vcalendar.replace(/(RRULE(?:;[^:\r\n]*)?:)([^\r\n]*)/gi, (line, prefix, rule) => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Whenever another property contains the substring Useful? React with 👍 / 👎. |
||
| return prefix + rule.replace(/(^|;)BYMONTHDAY=([^;]*)/i, (part, separator, days) => { | ||
| const normalizedDays = days.split(',').filter(Boolean).join(',') | ||
| return normalizedDays ? `${separator}BYMONTHDAY=${normalizedDays}` : '' | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Useful? React with 👍 / 👎. |
||
| }) | ||
| }) | ||
| } | ||
|
|
||
| export default class Task { | ||
|
|
||
| /** | ||
|
|
@@ -48,7 +63,7 @@ export default class Task { | |
| throw new Error('Invalid vCalendar') | ||
| } | ||
|
|
||
| const jCal = ICAL.parse(vcalendar) | ||
| const jCal = ICAL.parse(normalizeEmptyByMonthDayValues(vcalendar)) | ||
| if (jCal[0] !== 'vcalendar') { | ||
| throw new Error('Only one task is allowed in the vCalendar data') | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a CalDAV payload uses standard line folding before or within
BYMONTHDAY(for example,RRULE:FREQ=MONTHLY;\r\n BYMONTHDAY=,24), this pattern stops at the physical CR/LF and never examines the continuation.ICAL.parsethen unfolds the unchanged malformed value and rejects it, so the task/calendar disappearance this change is meant to prevent remains for folded recurrence rules; unfold the content line or include its continuations before sanitizing.Useful? React with 👍 / 👎.