- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 33.3k
          gh-114713: Handle case of an empty bytes object passed to zoneinfo.ZoneInfo
          #132582
        
          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
base: main
Are you sure you want to change the base?
Conversation
zoneinfo.ZoneInfozoneinfo.ZoneInfo
      |  | ||
|  | ||
| def _validate_tzfile_path(path, _base=_TEST_PATH): | ||
| if not path: | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wasn't correct.
If we pass None, instead of a TypeError we'll get a ValueError, so we need more exact check here.
| elif isinstance(path, bytes) and path == b"": | ||
| raise ValueError( | ||
| "ZoneInfo key must not be an empty bytes object" | ||
| ) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense maybe to just emit ZoneInfo key must not be empty for both string and bytes? Also, since we check for passed data types, does it make sense to also restrict them to str/bytes? Currently, passing for instance [] results in TypeError: unhashable type: 'list' somewhere down the road. Maybe worth returning meaningful exception saying what allowed types are? We anyway check passed in types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that makes sense. Though I think that the current approach is wrong.
We should insert these two checks (actually, bytes objects shouldn't be passed to the zoneinfo.ZoneInfo) to C and Python implementation of ZoneInfo.__new__:
- Check that keyis string (or subclass of string)
- Check that keyis a non-empty string.
 WDYM?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has conflicts now.
''#114713