-
Notifications
You must be signed in to change notification settings - Fork 444
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
Crash with double-slashes in /etc/localtime on Python 3.9 #990
Comments
Using babel version v2.11.0 with Python 3.9 does not give the error, so this becomes an issue in the latest versions. |
I just encountered this with Babel It looks like the problem is in localtime/_unix.py. The def _get_localzone(_root: str = '/') -> datetime.tzinfo:
"""Tries to find the local timezone configuration.
This method prefers finding the timezone name and passing that to
zoneinfo or pytz, over passing in the localtime file, as in the later
case the zoneinfo name is unknown.
The parameter _root makes the function look for files like /etc/localtime
beneath the _root directory. This is primarily used by the tests.
In normal usage you call the function without parameters.
"""
# <snip>
# This is actually a pretty reliable way to test for the local time
# zone on operating systems like OS X. On OS X especially this is the
# only one that actually works.
try:
link_dst = os.readlink('/etc/localtime')
except OSError:
pass
# <snip> |
I think the solution to this is to replace |
Need some working tests before attempting to fix python-babel#990. Refs python-babel#990
Need some working tests before attempting to fix python-babel#990. Refs python-babel#990
In certain OS installations, the target of /etc/localtime contains double slashes. This is a valid path, but not a valid zoneinfo key. This fix replaces `os.readlink` with `os.path.realpath`, which is guaranteed to return a normalized path. Fixes python-babel#990
In certain OS installations, the target of /etc/localtime contains double slashes. This is a valid path, but not a valid zoneinfo key. This fix replaces `os.readlink` with `os.path.realpath`, which is guaranteed to return a normalized path. Fixes python-babel#990
Need some working tests before attempting to fix python-babel#990. Refs python-babel#990
In certain OS installations, the target of /etc/localtime contains double slashes. This is a valid path, but not a valid zoneinfo key. This fix replaces `os.readlink` with `os.path.realpath`, which is guaranteed to return a normalized path. Fixes python-babel#990
Need some working tests before attempting to fix python-babel#990. Refs python-babel#990
In certain OS installations, the target of /etc/localtime contains double slashes. This is a valid path, but not a valid zoneinfo key. This fix replaces `os.readlink` with `os.path.realpath`, which is guaranteed to return a normalized path. Fixes python-babel#990
Confirmed this is also a problem with Python 3.10 on Ubuntu. |
Need some working tests before attempting to fix python-babel#990. Refs python-babel#990
In certain OS installations, the target of /etc/localtime contains double slashes. This is a valid path, but not a valid zoneinfo key. This fix replaces `os.readlink` with `os.path.realpath`, which is guaranteed to return a normalized path. Fixes python-babel#990
The broken unit tests have been fixed upstream. I rebased my fixes onto |
For anybody that needs a temporary workaround, I was able to fix this in an Ubuntu Docker image by recreating the rm -f /etc/localtime
ln -s /usr/share/zoneinfo/Etc/UTC /etc/localtime |
I'm having this issue with Ubuntu 22.04, python 3.10 and babel 2.13.
The strange thing is that my /etc/localtime does not have any slash... but it is quite strange anyway:
Don't know how to fix it. [EDIT] Sorry! Now I noticed that the double slash is on the filepath itself...
So this solution indeed fixed my error:
|
Overview Description
Importing
babel.localtime
crashes on Python 3.9 if/etc/localtime
contains double-slashes.Steps to Reproduce
Note the double-slash,
//UTC
.Actual Results
Crash.
Expected Results
No crash.
Reproducibility
Crashes for me on Python 3.9 with
babel
2.12.1
. Works on Python 3.8.The problem is that
babel.localtime._unix._get_localzone
has naive path handling.Additional Information
I'm not sure whether
babel
is to blame here, but since this is working on Python 3.8 it would be nice to makebabel
more robust here. As far as I can tell, double slashes are valid in POSIX and should be treated as single slashes.The text was updated successfully, but these errors were encountered: