fixed tilde expansion

This commit is contained in:
Anthony Scopatz 2016-09-09 19:21:26 -04:00
parent 1638cbadf7
commit 9f7c9ae817
3 changed files with 23 additions and 5 deletions

14
news/tildeassign.rst Normal file
View file

@ -0,0 +1,14 @@
**Added:** None
**Changed:** None
**Deprecated:** None
**Removed:** None
**Fixed:**
* Fixed issue where tilde expansion was occuring more than once before an
equals sign.
**Security:** None

View file

@ -127,9 +127,9 @@ def test_list_of_strs_or_callables(exp, inp):
'~',
'~/',
'x=~/place',
'one:~/place',
'one:~/place:~/yo',
'~/one:~/place:~/yo',
'x=one:~/place',
'x=one:~/place:~/yo',
'x=~/one:~/place:~/yo',
])
def test_expand_path(s, home_env):
if os.sep != '/':
@ -138,6 +138,7 @@ def test_expand_path(s, home_env):
s = s.replace(':', os.pathsep)
assert expand_path(s) == s.replace('~', HOME_PATH)
@pytest.mark.parametrize('kind', [str, 's', 'S', 'str', 'string'])
def test_convert_macro_arg_str(kind):
raw_arg = 'value'

View file

@ -108,8 +108,11 @@ def expand_path(s):
# first '='". See the following for more details.
# https://www.gnu.org/software/bash/manual/html_node/Tilde-Expansion.html
pre, char, post = s.partition('=')
s = pre + char + os.path.expanduser(post) if char else s
s = os.pathsep.join(map(os.path.expanduser, s.split(os.pathsep)))
if char:
s = os.path.expanduser(pre) + char
s += os.pathsep.join(map(os.path.expanduser, post.split(os.pathsep)))
else:
s = os.path.expanduser(s)
return s