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

Avoid infinite loop with invalid YEARLY recurrence rule #621

Merged
merged 4 commits into from
Apr 18, 2024

Conversation

leftmostcat
Copy link
Collaborator

@coveralls
Copy link

coveralls commented Sep 14, 2023

Pull Request Test Coverage Report for Build 8741965240

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 44 of 44 (100.0%) changed or added relevant lines in 1 file are covered.
  • 107 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.06%) to 97.98%

Files with Coverage Reduction New Missed Lines %
lib/ical/recur_iterator.js 107 89.63%
Totals Coverage Status
Change from base Build 8720865860: -0.06%
Covered Lines: 9356
Relevant Lines: 9532

💛 - Coveralls

lib/ical/recur_iterator.js Outdated Show resolved Hide resolved
Comment on lines 71 to 76
checkNoInstance({
freq: 'DAILY',
parts: {
BYYEARDAY: [200]
}
}, 'BYYEARDAY may only appear in YEARLY rules');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spec says that The BYYEARDAY rule part MUST NOT be specified when the FREQ rule part is set to DAILY, WEEKLY, or MONTHLY., so this combination should normally be an error instead of just not producing instances.

I guess that brings up the bigger question of should we just ignore such errors and be lenient, or should we throw. What about using ICAL.design.strict to determine if it should throw or silently show no instances?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The robustness principle suggests to me that we should only error if we reach a point where we simply can't interpret the file any longer. I'd be okay with using strict as a guard here if that makes sense to you. Probably the best thing to do in this instance is to favor the FREQ property and any invalid parts that follow are silently dropped, resulting in occurrences that follow whatever can be validly interpreted. Unfortunately, the spec provides rules for how to create valid iCalendar objects, but no real guidance on how to deal with invalid ones.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, generally I'd like ical.js to be able to parse everything and be lenient. The strict mode was meant for the case where you might use ical.js as a validator and would want it to bail. Let's put this behind the strict mode check.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't quite sure how to access whether we were in strict mode from the recurrence iter, so I've implemented the infinite loop prevention without modifying any throwing behavior. If that behavior is desire, it may be best to address that in a followup.

@titanism titanism mentioned this pull request Feb 16, 2024
@kewisch kewisch added the needinfo More information has been requested label Mar 25, 2024
Copy link

github-actions bot commented Apr 2, 2024

It looks like we haven't heard back on this issue, therefore we are closing this issue. If this problem persists in the latest version of ical.js, please re-open this issue.

@github-actions github-actions bot closed this Apr 2, 2024
@github-actions github-actions bot removed the needinfo More information has been requested label Apr 2, 2024
@leftmostcat leftmostcat reopened this Apr 17, 2024
@leftmostcat
Copy link
Collaborator Author

I've addressed the comments left. The timezones CI job seems to be failing due to something entirely unrelated that I don't understand.

@@ -1360,4 +1384,11 @@ class RecurIterator {
return result;
}
}

class InvalidRecurrenceRuleError extends Error {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some jsdoc here?

Copy link
Owner

@kewisch kewisch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+wc, thank you!

let iterator = recur.iterator(start);

if (options.noInstance) {
assert.equal(iterator.next(), null);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also assert that completed is set, while you are at it.

@leftmostcat leftmostcat merged commit b804030 into kewisch:main Apr 18, 2024
7 checks passed
@leftmostcat leftmostcat deleted the es6-invalid-rrule-fix branch April 18, 2024 17:10
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

Successfully merging this pull request may close these issues.

3 participants