arrow-py / arrow

🏹 Better dates & times for Python
https://arrow.readthedocs.io
Apache License 2.0
8.73k stars 684 forks source link

parser(fix): more robust (UTC prefix in TzInfoParser #1165

Open kroozo opened 1 year ago

kroozo commented 1 year ago

Pull Request Checklist

Thank you for taking the time to improve Arrow! Before submitting your pull request, please check all appropriate boxes:

If you have any questions about your code changes or any of the points above, please submit your questions along with the pull request and we will try our best to help!

Description of Changes

The changes introduced in this PR comes with unintended side effects: It removed the end of string matching from the regex to allow for the arbitrary information at the end of the string. The intention was to match time zones like this: "(UTC+01:00) Amsterdam, Berlin, Bern, Rom, Stockholm, Wien"

This however applied to input without the "(UTC" prefix, so things like: +01:00.23 would also be handled by the code, and silently treated like "+01:00" which sounds bad. Also, misformats like this :"(UTC+01:00 Amsterdam, Berlin, Bern, Rom, Stockholm, Wien" would silently pass

The updated regex takes this into consideration, makes the closing parenthesis mandatory, and will not allow postfixes unless the string starts with the UTC prefix in parenthesis.

Notes

While this PR keeeps the original intention working, note that such timezone declarations are not valid in ISO (as far as I can tell without buying the standard :)), so it's a bit misleading.

Also, after treating the special cases here the work is basically dumped to dateutil's tz, which also seem to do some strange stuff. It'll return a tzstr for monstorities like "(UTC+01:00 Amsterdam whatver else even if it is very long as long as you dont have a comma", which probably shouln't be like that, but I really did not want to stir that much into a codebase where I don't get the intentions, so for now it behaves the same way it did before these 2 PRs , but it probably could be made better :)

We've been using this to make sure user input is valid TZ, so it's a bit of a bummer.

codecov[bot] commented 1 year ago

Codecov Report

All modified lines are covered by tests :white_check_mark:

Comparison is base (87a1a77) 100.00% compared to head (edf6f2a) 100.00%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1165 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 10 10 Lines 2326 2326 Branches 400 400 ========================================= Hits 2326 2326 ``` | [Files](https://app.codecov.io/gh/arrow-py/arrow/pull/1165?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=arrow-py) | Coverage Δ | | |---|---|---| | [arrow/parser.py](https://app.codecov.io/gh/arrow-py/arrow/pull/1165?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=arrow-py#diff-YXJyb3cvcGFyc2VyLnB5) | `100.00% <100.00%> (ø)` | |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.