Repository navigation
fix(prop): reject a zero-length period - #2103
rahul05ranjan wants to merge 3 commits into
Conversation
vPeriod raised ValueError only when the start came after the end, so a period whose end equaled its start - written either as two equal date-times or as a zero duration - was accepted and serialized back out. RFC 5545 section 3.3.9 requires the end of a period to come after its start, so a period with no length is as invalid as a reversed one. Reject start == end with the same ValueError the reversed case gets. The message now says the start is not before the end, which covers both cases, and the one test matching the old message is updated. Fixes PyCalendar#2087 Co-authored-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com>
RFC 5545 section 3.3.9 defines the period-start form with a positive duration, so a zero duration is as invalid as a negative one. The xCal parser's check now matches, raising the same "Expected positive duration" XCalParsingError for P0D, and the xCal test fixtures move the zero-duration specs from the valid round-trip lists to the invalid ones, where they already belonged: the constructor's start >= end rejection from the previous commit caught them first. Co-authored-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com>
|
Thanks for the pull request, @rahul05ranjan! A maintainer will review it shortly. |
|
One or more PR-quality checks did not pass. Review the PR Quality Checks summary in the workflow run for the failed checks and their details, then make any necessary updates. Checklist items may remain unchecked while work is in progress. Please tick each item as you complete it. If you used AI assistance, follow the project's Responsible AI use policy and provide the required disclosures. |
|
76d7918b2a87 |
Automated contributor detected@rahul05ranjan did not pass an automated contributor check on this pull request. If you believe this is a mistake, leave a comment and a maintainer will review it. Automated check by AgentScan |
angatha
left a comment
There was a problem hiding this comment.
Changes itself look fine
| @@ -0,0 +1 @@ | |||
| :class:`~icalendar.prop.dt.period.vPeriod` now rejects a zero-length period whose end equals its start, as :rfc:`5545#section-3.3.9` requires the end to come after the start. | |||
There was a problem hiding this comment.
Please add your github handle
Co-authored-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com>
|
Done in 6b4f970 — added the handle following the convention in the other news entries. |
Linked issue
Description
vPeriodrejected a period only when the start came strictly after the end, so a zero-length period was accepted, parsed, and written back out. RFC 5545 section 3.3.9 defines both period forms strictly:period-explicit: "The start MUST be before the end."period-start: "a start and positive duration of time."So a period whose end equals its start — written either as two equal date-times or as a zero duration (
P0D) — is as invalid as a reversed one.The constructor's comparison changes from
start > endtostart >= end, so both of the issue's cases get the sameValueErroras a reversed period:>>> vPeriod((start, start)) ValueError: Start time is not before end time >>> vPeriod((start, timedelta(0))) ValueError: Start time is not before end timeThe message now says the start is not before the end, accurate for the equal case as well; the one existing test matching the old wording is updated. This covers every construction path — direct construction,
from_icalround-trips throughvDDDTypes, jCal and xCal parsing — since they all build the period through this constructor.Two follow-ups in the same PR, both consequences of the same RFC rule:
XCalParsingError("Expected positive duration")only for negative durations; it now raises it for a zero duration too (P0D), with the same message.(start, P0D)among the valid round-trip specs; those two specs move to the invalid list, where the RFC puts them. No other test in the suite uses a zero-length period (verified by grepping the whole test tree forP0D/DURATION_0in period contexts).Dates read as midnight keep working; a period from one midnight to the next is unaffected because its end is a day after its start.
Checklist
Additional information
Verification run locally with system Python 3.13.5 (
PYTHONPATH=src python3 -m pytest), no extra dependencies needed:src/icalendar/tests/prop/test_vPeriod.py,test_period.py,test_issue_1633.py,test_equality.py, and the fullsrc/icalendar/tests/rfc_7265_jcal/andsrc/icalendar/tests/rfc_6321_xcal/directories (all period, jCal and xCal suites): 5731 + 3614 collected runs green, including two new parametrized rejection cases and a regression test for the issue's exact repro — both fail on the un-fixed HEAD. The xCalP0Dspecs now assert the "Expected positive duration" error.mainin a worktree shows identical failure sets except for the period-related tests fixed here:mainand this branch both have 585 environment-related failures (time-zone identification and Sphinx-version-directive tests, broken identically on both sides — the host has a newer dateutil/Sphinx than the repo pins), and this branch additionally had the 36 xCal zero-duration tests before the fixture move, which now pass.ValueError(the full-suite checkbox is left for CI; the suites listed above were run in full locally).I used AI to assist me with this change.