You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
sys.path[0] is incorrect if PYTHONFSENCODING is used #54223
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2010-10-13.22:25:10.615>created_at=<Date2010-10-02.12:14:21.087>labels= ['expert-unicode']
title='sys.path[0] is incorrect if PYTHONFSENCODING is used'updated_at=<Date2010-10-13.22:25:10.614>user='https://github.com/vstinner'
The problem is that PySys_SetArgvEx() inserts argv[0] at sys.path[0], but argv[0] is decoded using the locale encoding (by _Py_char2wchar() in main()), whereas paths of sys.path are supposed to be encodable (and decoded) by sys.getfilesystemencoding().
argv array should be decoded using the filesystem encoding (see issue bpo-9992) or argv[0] should be redecoded (encode to the locale encoding, and decode from the filesystem encoding, see issue bpo-9630).
r85302: _wrealpath() and _Py_wreadlink() support surrogates in the input path.
--
realpath_fs_encoding.patch: patch _wrealpath() to encode the resulting path with the filesystem encoding (with surrogateescape) instead of the locale encoding. This patch is incomplete: it doesn't fix the issue for non-Windows platforms without the realpath() function.
redecode_filename.patch (from issue bpo-10039) + realpath_fs_encoding.patch fix this issue on my Linux (Debian Sid) box.
Activity
vstinner commentedon Oct 2, 2010
In the following example, sys.path[0] should be '/home/SHARE/SVN/py3k\udcc3\udca9' (my locale and filesystem encodings are utf-8):
The problem is that PySys_SetArgvEx() inserts argv[0] at sys.path[0], but argv[0] is decoded using the locale encoding (by _Py_char2wchar() in main()), whereas paths of sys.path are supposed to be encodable (and decoded) by sys.getfilesystemencoding().
argv array should be decoded using the filesystem encoding (see issue bpo-9992) or argv[0] should be redecoded (encode to the locale encoding, and decode from the filesystem encoding, see issue bpo-9630).
vstinner commentedon Oct 6, 2010
Not only PySys_SetArgvEx(). There is another issue with RunMainFromImporter() which do: sys.path[0] = filename
vstinner commentedon Oct 7, 2010
See also issue bpo-10039.
vstinner commentedon Oct 7, 2010
This issue depends on issue bpo-10039.
vstinner commentedon Oct 7, 2010
r85302: _wrealpath() and _Py_wreadlink() support surrogates in the input path.
--
realpath_fs_encoding.patch: patch _wrealpath() to encode the resulting path with the filesystem encoding (with surrogateescape) instead of the locale encoding. This patch is incomplete: it doesn't fix the issue for non-Windows platforms without the realpath() function.
redecode_filename.patch (from issue bpo-10039) + realpath_fs_encoding.patch fix this issue on my Linux (Debian Sid) box.
vstinner commentedon Oct 7, 2010
I just created Python/fileutils.c: update the patch for this new file.
vstinner commentedon Oct 13, 2010
Fixed by r85430 (remove PYTHONFSENCODING), see bpo-9992.