[New-bugs-announce] [issue5827] os.path.normpath doesn't preserve unicode

Matt Giuca report at bugs.python.org
Fri Apr 24 06:23:59 CEST 2009

New submission from Matt Giuca <matt.giuca at 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'')
>>> os.path.normpath(u'.')
>>> os.path.normpath(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 <report at bugs.python.org>

More information about the New-bugs-announce mailing list