[Python-bugs-list] [Bug #110606] ntpath.expandvars doesn't handle case properly (PR#162)

noreply@sourceforge.net noreply@sourceforge.net
Tue, 22 Aug 2000 16:33:21 -0700


Bug #110606, was updated on 2000-Jul-31 17:05
Here is a current snapshot of the bug.

Project: Python
Category: Windows
Status: Open
Resolution: None
Bug Group: None
Priority: 5
Summary: ntpath.expandvars doesn't handle case properly (PR#162)

Details: Jitterbug-Id: 162
Submitted-By: dwr2@ix.netcom.com
Date: Sun, 19 Dec 1999 08:38:21 -0500 (EST)
Version: 1.5
OS: Windows 95


When accessing os.environ under Windows 95/NT/etc., lower-case environment
variable names are automatically converted to upper-case before use.
However, ntpath.expandvars does not accept lower-case variable names.
This is inconsistent.
This also happens in dospath.expandvars and may happen in os2path.expandvars.

Here is a Python session demonstrating the problem:

>>> import os
>>> os.name
'nt'
>>> os.environ['abc']='xyz'
>>> os.environ['abc']
'xyz'
>>> os.path.expandvars('$abc')
''
>>> os.path.expandvars('$ABC')
'xyz'
>>> 

Note that you can access os.environ using a lower-case name, but you must use
upper-case for os.path.expandvars (-->ntpath.expandvars).
This can easily be fixed by changing "os.environ.has_key(var)" to
"os.environ.has_key(string.upper(key))" in two places in each of
ntpath.expandvars, dospath.expandvars, and possibly os2path.expandvars.
Another solution would be to add the following function to os._Environ, in the
"if name in ('os2', 'nt', 'dos')" block:
    def has_key(self, key): return UserDict.UserDict.has_key(self,
string.upper(key))
The latter solution seems better to me, but I don't know the possible negative
ramifications of making such a change to a class used in so many places.
(On the other had, it is consistent with the definitions of _Environ.__getitem__
and _Environ.__setitem__.)

Further argument that lower-case should be accepted in ntpath.expandvars:
A DOS window opened in Windows 95 expands a lower-case variable name, despite
the actual variable name being stored in upper-case:
C:\WINDOWS>set abc=xyz
C:\WINDOWS>set
[...(most of variable list elided)...]
ABC=xyz
C:\WINDOWS>echo %abc%
xyz



====================================================================
Audit trail:
Mon Jan 17 09:05:54 2000	guido	moved from incoming to open

For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=110606&group_id=5470