mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
Fixed ntpath.expandvars to not replace references to non-existing
variables with nothing. Also added tests. This fixes bug #494589.
This commit is contained in:
parent
fa3d08b4a9
commit
33a0a06d31
4 changed files with 32 additions and 2 deletions
|
|
@ -344,8 +344,10 @@ def expandvars(path):
|
|||
var = path[:index]
|
||||
if var in os.environ:
|
||||
res = res + os.environ[var]
|
||||
else:
|
||||
res = res + '${' + var + '}'
|
||||
except ValueError:
|
||||
res = res + path
|
||||
res = res + '${' + path
|
||||
index = pathlen - 1
|
||||
else:
|
||||
var = ''
|
||||
|
|
@ -357,8 +359,10 @@ def expandvars(path):
|
|||
c = path[index:index + 1]
|
||||
if var in os.environ:
|
||||
res = res + os.environ[var]
|
||||
else:
|
||||
res = res + '$' + var
|
||||
if c != '':
|
||||
res = res + c
|
||||
index = index - 1
|
||||
else:
|
||||
res = res + c
|
||||
index = index + 1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue