Repository navigation
Conversation
vFloat.to_ical() and vGeo.to_ical() wrote very small and very large numbers as 1e-05, which RFC 5545 section 3.3.7 does not allow. Closes PyCalendar#2136
|
Thanks for the pull request, @fermsp! A maintainer will review it shortly. |
Insufficient dataNot enough activity yet to make a reliable assessment. This is an automated analysis by AgentScan |
| @@ -0,0 +1 @@ | |||
| Fixed :class:~icalendar.prop.float.vFloat and :class:~icalendar.prop.geo.vGeo writing very small and very large numbers with an exponent, such as GEO:1e-05;-2e-05. The FLOAT value type of :rfc:5545#section-3.3.7 does not allow an exponent. @fermsp | |||
There was a problem hiding this comment.
Thanks for your quick response and contribution.
Let's polish up the reStructuredText in this news fragment so that it links. You can check how it renders in the pull request preview under the CI check for docs/readthedocs.org:icalendar under Reference > Change log.
| Fixed :class:~icalendar.prop.float.vFloat and :class:~icalendar.prop.geo.vGeo writing very small and very large numbers with an exponent, such as GEO:1e-05;-2e-05. The FLOAT value type of :rfc:5545#section-3.3.7 does not allow an exponent. @fermsp | |
| Fixed :class:`~icalendar.prop.float.vFloat` and :class:`~icalendar.prop.geo.vGeo` to write very small and very large numbers without an exponent, instead of, for example, ``GEO:1e-05;-2e-05``. The FLOAT value type of :rfc:`5545#section-3.3.7` does not allow an exponent. @fermsp |
Otherwise this looks good to me, and I'll pass it over to a maintainer for final review.
aplatogg
left a comment
There was a problem hiding this comment.
Reviewed against your branch locally (PYTHONPATH pointed at your src/, pytest src/icalendar/tests/test_issue_2136_float_exponent.py src/icalendar/tests/prop): 1298 passed, 1 skipped. The approach is right and the output matches what #2136 asks for. Three points, in priority order.
1. news/2136.bugfix needs backticks around the roles. As written, the entry renders them as literal text instead of links:
Fixed :class:~icalendar.prop.float.vFloat writing values.
For Fixed :class:~... I rendered that through docutils and got the string back unchanged. Every other fragment in news/ writes :class:`~icalendar.prop.float.vFloat` and :rfc:`5545#section-3.3.7` with backticks, e.g. news/1084.bugfix. Both roles in that sentence need them.
2. inf/nan still write an invalid FLOAT, unchanged by this PR. vFloat(float("inf")).to_ical() is b'inf', which the grammar does not allow, because _float_to_ical only rewrites a repr that contains e. from_ical rejects those values, so nothing new is broken here, and I would keep the fix out of this PR. A math.isfinite() guard before formatting is where it would go if you want it later.
3. Optional, test placement. tests/prop/test_vFloat.py holds the vFloat tests and the vGeo assertions live in tests/prop/test_unit.py. A dedicated test_issue_2136_* file works, but folding the four cases into those two files may be what a maintainer asks for. No functional difference.
For the record, what I checked on your branch beyond the test suite: 0.1 -> b'0.1', so the shortest representation survives instead of expanding to full precision; 0.0 -> b'0.0'; -0.0 -> b'-0.0'; 1e16 -> b'10000000000000000'; 5e-324 writes 326 digits and parses back to the same float; vGeo((0.0, -0.0)) -> '0.0;-0.0'.
I had an independent PR for this (#2139) and closed it, so this is the only one open for #2136.
Linked issue
Description
vFloat.to_ical()andvGeo.to_ical()wrote very small and very large numbers with an exponent, such asGEO:1e-05;-2e-05. The FLOAT value type of RFC 5545 has none. These values are now written with all their digits. Other values, xCal and jCal are unchanged.Checklist