problem with safe_join function from django.utils._os
|Reported by:||Gonzalo Delgado||Owned by:||Karen Tracey|
|Severity:||Keywords:||bug utils _os safe_join|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||yes||Patch needs improvement:||yes|
The directory I use for most of my programming work is '/home/gonzalo/Código' (código is spanish for "code").
Since my django projects live inside that directory, TEMPLATE_DIRS always contains it.
I got this problem when loading templates from an app within that directory (Django hinted: "The string that could not be encoded/decoded was: alo/C��digo")
This problem best explained with this example:
$ cd Código/ $ python Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from django.utils import _os >>> _os.safe_join('spam', 'eggs') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.5/site-packages/django/utils/_os.py", line 16, in safe_join final_path = normcase(abspath(join(base, *paths))) File "/usr/lib/python2.5/posixpath.py", line 403, in abspath path = join(os.getcwd(), path) File "/usr/lib/python2.5/posixpath.py", line 65, in join path += '/' + b UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 15: ordinal not in range(128)
safe_join uses force_unicode to convert 'spam' and 'eggs' to unicode objects, but then uses os.path.abspath which obtains the working directory ('/home/gonzalo/Código') and tries to join it with u'spam' and u'eggs' and fails.
Change History (12)
comment:4 follow-up: 5 Changed 8 years ago by
|Owner:||changed from nobody to Karen Tracey|
|Status:||new → assigned|
|Triage Stage:||Unreviewed → Accepted|