os.path.expanduser doesn't handle Unicode when ~ expands to a non-ASCII path

Bug #242179 reported by Jesús Corrius
2
Affects Status Importance Assigned to Milestone
Moovida
Fix Released
Undecided
Unassigned
0.3
Won't Fix
Undecided
Unassigned

Bug Description

os.path.expanduser (on both UNIX and Windows) doesn't handle Unicode when ~ expands to a non-ASCII path. Therefore, a byte string must be passed in and the result decoded:

home = os.path.expanduser("~").decode(sys.getfilesystemencoding())

For example, in my home computer:

>>> import os.path
>>> os.path.expanduser('~')
'C:\\Documents and Settings\\Jes\xfas'
>>> os.path.expanduser("~").decode(sys.getfilesystemencoding())
'C:\Documents and Settings\Jesús'

Code like this in elisa/core/plugin_registry (in the 0.3.5 branch, i don't have 0.5 here) is broken:

DEFAULT_PLUGIN_DIR = os.path.expanduser('~/.elisa/plugins')

Revision history for this message
Gernot (gernot-fluendo) wrote :

instead of sys.getfilesystemencoding() use locale.getdefaultlocale()[1] or even better use system_encoding() from elisa.core.utils.locale_helper
sys.getfilesystemencoding() returns on win32 always 'mbcs' which is hardcoded in python.

Revision history for this message
Gernot (gernot-fluendo) wrote :

the problem with os.path.expanduser and other path functions in python is not that they don't work correctly, but if you interprete the result as utf8 it won't work because it will not alwayls be a utf8 encoded byte string returned.
in the elisa.extern.path module, when like in plugin_registry, a str is passed it gets decoded to unicode using utf8, which is wrong.
because of this, now we pass a unicode string which is decoded using the system locale.
also, the plugin_registry code contained a hardcoded encode to utf8 line.

Changed in elisa:
status: New → Fix Committed
Changed in elisa:
status: Fix Committed → Fix Released
Revision history for this message
Olivier Tilloy (osomon) wrote :

Elisa is not maintained any longer, the 0.3 series even less...

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.