arrow
arrow copied to clipboard
parser(fix): more robust (UTC prefix in TzInfoParser
Pull Request Checklist
Thank you for taking the time to improve Arrow! Before submitting your pull request, please check all appropriate boxes:
- [x] 🧪 Added tests for changed code.
- [x] 🛠️ All tests pass when run locally (run
tox
ormake test
to find out!). - [x] 🧹 All linting checks pass when run locally (run
tox -e lint
ormake lint
to find out!). - [ ] 📚 Updated documentation for changed code.
- [x] ⏩ Code is up-to-date with the
master
branch.
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 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
@@ Coverage Diff @@
## master #1165 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 10 10
Lines 2326 2326
Branches 400 400
=========================================
Hits 2326 2326
Files | Coverage Δ | |
---|---|---|
arrow/parser.py | 100.00% <100.00%> (ø) |
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.