New submission from Matt Giuca <matt.gi...@gmail.com>:

In the Python 2.x branch, os.path.normpath will sometimes return a str
even if given a unicode. This is not an issue in the Python 3.0 branch.

This happens specifically when it throws away all string data and
constructs its own:

>>> os.path.normpath(u'')
'.'
>>> os.path.normpath(u'.')
'.'
>>> os.path.normpath(u'/')
'/'

This is a problem if working with code which expects all strings to be
unicode strings (sometimes, functions raise exceptions if given a str,
when expecting a unicode).

I have attached patches (with test cases) for posixpath and ntpath which
correctly preserve the unicode-ness of the input string, such that the
new behaviour is:

>>> os.path.normpath(u'')
u'.'
>>> os.path.normpath(u'.')
u'.'
>>> os.path.normpath(u'/')
u'/'

I tried it on os2emxpath and plat-riscos/riscospath (the other two
OS-specific path modules), and it already worked fine for them.
Therefore, this patch fixes all necessary OS-specific versions of os.path.

----------
components: Library (Lib), Unicode
files: normpath.patch
keywords: patch
messages: 86395
nosy: mgiuca
severity: normal
status: open
title: os.path.normpath doesn't preserve unicode
versions: Python 2.6, Python 2.7
Added file: http://bugs.python.org/file13757/normpath.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue5827>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to