Repository navigation
cap transitions of a VTIMEZONE RRULE #2047
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
Open
shamsManna
wants to merge
5
commits into
PyCalendar:main
Choose a base branch
from
shamsManna:vtimezone-rrule-transition-cap
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fe106a2
cap transitions of a VTIMEZONE RRULE
shamsManna 9e4e42f
drop the lambda in the transition count and test the PR example
shamsManna 98233dc
go back to takewhile and make the transition tests fail fast without …
shamsManna c0b38ad
Merge branch 'main' into vtimezone-rrule-transition-cap
angatha 3b9851a
only allow FREQ=YEARLY in a VTIMEZONE RRULE
shamsManna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Reject a VTIMEZONE whose RRULE does not have ``FREQ=YEARLY``. Timezones created from a VTIMEZONE expand its RRULE from DTSTART, so a calendar with an RRULE such as ``FREQ=SECONDLY`` in a VTIMEZONE could exhaust memory and CPU when it was parsed or when a date in that timezone was used. I used AI to assist me with this change. @shamsManna |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/icalendar/tests/calendars/pr_2047_vtimezone_secondly_rrule_ical.ics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| BEGIN:VCALENDAR | ||
| BEGIN:VTIMEZONE | ||
| TZID:Custom | ||
| BEGIN:STANDARD | ||
| DTSTART:19700101T000000 | ||
| RRULE:FREQ=SECONDLY | ||
| TZOFFSETFROM:+0100 | ||
| TZOFFSETTO:+0000 | ||
| END:STANDARD | ||
| BEGIN:DAYLIGHT | ||
| DTSTART:19700601T000000 | ||
| RRULE:FREQ=YEARLY | ||
| TZOFFSETFROM:+0000 | ||
| TZOFFSETTO:+0100 | ||
| END:DAYLIGHT | ||
| END:VTIMEZONE | ||
| BEGIN:VEVENT | ||
| UID:a | ||
| DTSTART;TZID=Custom:20250101T120000 | ||
| END:VEVENT | ||
| END:VCALENDAR |
37 changes: 37 additions & 0 deletions
37
src/icalendar/tests/calendars/pr_2047_vtimezone_secondly_rrule_jcal.jcal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| ["vcalendar", | ||
| [], | ||
| [ | ||
| ["vtimezone", | ||
| [ | ||
| ["tzid", {}, "text", "Custom"] | ||
| ], | ||
| [ | ||
| ["standard", | ||
| [ | ||
| ["dtstart", {}, "date-time", "1970-01-01T00:00:00"], | ||
| ["rrule", {}, "recur", {"freq": "SECONDLY"}], | ||
| ["tzoffsetfrom", {}, "utc-offset", "+01:00"], | ||
| ["tzoffsetto", {}, "utc-offset", "+00:00"] | ||
| ], | ||
| [] | ||
| ], | ||
| ["daylight", | ||
| [ | ||
| ["dtstart", {}, "date-time", "1970-06-01T00:00:00"], | ||
| ["rrule", {}, "recur", {"freq": "YEARLY"}], | ||
| ["tzoffsetfrom", {}, "utc-offset", "+00:00"], | ||
| ["tzoffsetto", {}, "utc-offset", "+01:00"] | ||
| ], | ||
| [] | ||
| ] | ||
| ] | ||
| ], | ||
| ["vevent", | ||
| [ | ||
| ["uid", {}, "text", "a"], | ||
| ["dtstart", {"tzid": "Custom"}, "date-time", "2025-01-01T12:00:00"] | ||
| ], | ||
| [] | ||
| ] | ||
| ] | ||
| ] |
67 changes: 67 additions & 0 deletions
67
src/icalendar/tests/calendars/pr_2047_vtimezone_secondly_rrule_xcal.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <icalendar xmlns="urn:ietf:params:xml:ns:icalendar-2.0"> | ||
| <vcalendar> | ||
| <components> | ||
| <vtimezone> | ||
| <properties> | ||
| <tzid> | ||
| <text>Custom</text> | ||
| </tzid> | ||
| </properties> | ||
| <components> | ||
| <standard> | ||
| <properties> | ||
| <dtstart> | ||
| <date-time>1970-01-01T00:00:00</date-time> | ||
| </dtstart> | ||
| <rrule> | ||
| <recur> | ||
| <freq>SECONDLY</freq> | ||
| </recur> | ||
| </rrule> | ||
| <tzoffsetfrom> | ||
| <utc-offset>+01:00</utc-offset> | ||
| </tzoffsetfrom> | ||
| <tzoffsetto> | ||
| <utc-offset>+00:00</utc-offset> | ||
| </tzoffsetto> | ||
| </properties> | ||
| </standard> | ||
| <daylight> | ||
| <properties> | ||
| <dtstart> | ||
| <date-time>1970-06-01T00:00:00</date-time> | ||
| </dtstart> | ||
| <rrule> | ||
| <recur> | ||
| <freq>YEARLY</freq> | ||
| </recur> | ||
| </rrule> | ||
| <tzoffsetfrom> | ||
| <utc-offset>+00:00</utc-offset> | ||
| </tzoffsetfrom> | ||
| <tzoffsetto> | ||
| <utc-offset>+01:00</utc-offset> | ||
| </tzoffsetto> | ||
| </properties> | ||
| </daylight> | ||
| </components> | ||
| </vtimezone> | ||
| <vevent> | ||
| <properties> | ||
| <uid> | ||
| <text>a</text> | ||
| </uid> | ||
| <dtstart> | ||
| <parameters> | ||
| <tzid> | ||
| <text>Custom</text> | ||
| </tzid> | ||
| </parameters> | ||
| <date-time>2025-01-01T12:00:00</date-time> | ||
| </dtstart> | ||
| </properties> | ||
| </vevent> | ||
| </components> | ||
| </vcalendar> | ||
| </icalendar> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| """A VTIMEZONE RRULE must repeat yearly. | ||
|
|
||
| Timezones created from a VTIMEZONE expand its RRULE from DTSTART. | ||
| An RRULE such as FREQ=SECONDLY could exhaust memory or CPU. | ||
| """ | ||
|
|
||
| import dateutil.rrule | ||
| import pytest | ||
|
|
||
| from icalendar import vRecur | ||
|
|
||
| # Far more than any test here needs, small enough to stop in seconds. | ||
| MAX_EXPANDED_TRANSITIONS = 10_000 | ||
|
|
||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def bounded_rrule_expansion(monkeypatch): | ||
| """Fail fast instead of hanging if an RRULE is expanded without a limit.""" | ||
| expand = dateutil.rrule.rrule._iter | ||
|
|
||
| def bounded_expand(self): | ||
| for count, dt in enumerate(expand(self)): | ||
| if count >= MAX_EXPANDED_TRANSITIONS: | ||
| pytest.fail( | ||
| f"RRULE expanded to more than {MAX_EXPANDED_TRANSITIONS} transitions" | ||
| ) | ||
| yield dt | ||
|
|
||
| monkeypatch.setattr(dateutil.rrule.rrule, "_iter", bounded_expand) | ||
|
|
||
|
|
||
| SECONDLY_ICAL = "pr_2047_vtimezone_secondly_rrule_ical.ics" | ||
| SECONDLY_JCAL = "pr_2047_vtimezone_secondly_rrule_jcal.jcal" | ||
| SECONDLY_XCAL = "pr_2047_vtimezone_secondly_rrule_xcal.xml" | ||
|
|
||
|
|
||
| def test_secondly_rrule_from_1970_is_invalid(calendars): | ||
| """Reading the offset of an event in a SECONDLY timezone fails fast. | ||
|
|
||
| Without the check, this exhausts memory. | ||
| """ | ||
| with pytest.raises(ValueError, match="FREQ=YEARLY"): | ||
| calendars[SECONDLY_ICAL].events[0].DTSTART.utcoffset() | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("source", [SECONDLY_ICAL, SECONDLY_JCAL, SECONDLY_XCAL]) | ||
| @pytest.mark.parametrize("method", ["to_tz", "get_transitions"]) | ||
| def test_secondly_rrule_is_invalid_in_all_formats(calendars, tzp, source, method): | ||
| """iCalendar, jCal and xCal reject the timezone.""" | ||
| with pytest.raises(ValueError, match="FREQ=YEARLY"): | ||
| timezone = calendars[source].timezones[0] | ||
| if method == "to_tz": | ||
| timezone.to_tz(tzp, lookup_tzid=False) | ||
| else: | ||
| timezone.get_transitions() | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "freq", ["SECONDLY", "MINUTELY", "HOURLY", "DAILY", "WEEKLY", "MONTHLY"] | ||
| ) | ||
| def test_rrule_that_does_not_repeat_yearly_is_invalid(timezones, tzp, freq): | ||
| """Only a yearly RRULE is valid in a timezone.""" | ||
| timezone = timezones.pacific_fiji | ||
| timezone.standard[0]["RRULE"] = vRecur.from_ical(f"FREQ={freq}") | ||
| with pytest.raises(ValueError, match="FREQ=YEARLY"): | ||
| timezone.to_tz(tzp, lookup_tzid=False) | ||
| with pytest.raises(ValueError, match="FREQ=YEARLY"): | ||
| timezone.get_transitions() | ||
|
|
||
|
|
||
| def test_yearly_rrule_is_used(timezones, tzp): | ||
| """A yearly RRULE with BYxxx parts still works.""" | ||
| assert timezones.pacific_fiji.to_tz(tzp, lookup_tzid=False) is not None | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.