Skip to content

Commit 20a97c0

Browse files
committed
Handle quotes around setting paths
1 parent 3ecdd5f commit 20a97c0

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

src/tox/config/__init__.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,8 +1944,11 @@ def processcommand(cls, reader, command, replace=True):
19441944
continue
19451945

19461946
new_arg = ""
1947+
has_dual_quote = "''" in word
19471948
new_word = reader._replace(word, unquote_path=False)
19481949
new_word = reader._replace(new_word, unquote_path=False)
1950+
if not has_dual_quote:
1951+
new_word = new_word.replace("''", "'")
19491952
new_word = new_word.replace("\\{", "{").replace("\\}", "}")
19501953
new_arg += new_word
19511954
newcommand += new_arg
@@ -1980,8 +1983,14 @@ def word_has_ended():
19801983
and ps.word
19811984
and ps.word[-1] not in string.whitespace
19821985
)
1983-
or (cur_char == "{" and ps.depth == 0 and not ps.word.endswith("\\"))
1984-
or (ps.depth == 0 and ps.word and ps.word[-1] == "}")
1986+
or (
1987+
cur_char == "{"
1988+
and ps.depth == 0
1989+
and not ps.word.endswith("\\")
1990+
and ps.word != "'"
1991+
)
1992+
or (ps.depth == 0 and ps.word and ps.word[-1] == "}" and peek() != "'")
1993+
or (ps.depth == 0 and ps.word and ps.word[-2:] == "}'")
19851994
or (cur_char not in string.whitespace and ps.word and ps.word.strip() == "")
19861995
)
19871996

@@ -1995,6 +2004,12 @@ def yield_if_word_ended():
19952004
if word_has_ended():
19962005
yield_this_word()
19972006

2007+
def peek():
2008+
try:
2009+
return self.command[_i + 1]
2010+
except IndexError:
2011+
return ""
2012+
19982013
def accumulate():
19992014
ps.word += cur_char
20002015

@@ -2004,7 +2019,7 @@ def push_substitution():
20042019
def pop_substitution():
20052020
ps.depth -= 1
20062021

2007-
for cur_char in self.command:
2022+
for _i, cur_char in enumerate(self.command):
20082023
if cur_char in string.whitespace:
20092024
if ps.depth == 0:
20102025
yield_if_word_ended()
@@ -2016,6 +2031,12 @@ def pop_substitution():
20162031
elif cur_char == "}":
20172032
accumulate()
20182033
pop_substitution()
2034+
elif cur_char == "'":
2035+
if ps.depth == 0 and ps.word[:2] == "'{" and ps.word[-1] == "}":
2036+
accumulate()
2037+
else:
2038+
yield_if_word_ended()
2039+
accumulate()
20192040
else:
20202041
yield_if_word_ended()
20212042
accumulate()

tests/unit/config/test_config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ def test_command_substitution_pound(self, tmpdir, newconfig):
526526
toxworkdir = {toxinidir}/.tox#dir
527527
528528
[testenv:py27]
529-
commands = {envpython} {toxworkdir}
529+
commands = '{envpython}' '{toxworkdir}'/'foo#bar'
530530
""",
531531
)
532532

@@ -541,7 +541,7 @@ def test_command_substitution_pound(self, tmpdir, newconfig):
541541

542542
assert envconfig.commands[0] == [
543543
str(envconfig.envbindir.join("python")),
544-
str(config.toxworkdir.realpath()),
544+
str(config.toxworkdir.realpath().join("foo#bar")),
545545
]
546546

547547
def test_command_substitution_whitespace(self, tmpdir, newconfig):
@@ -552,7 +552,7 @@ def test_command_substitution_whitespace(self, tmpdir, newconfig):
552552
toxworkdir = {toxinidir}/.tox dir
553553
554554
[testenv:py27]
555-
commands = {envpython} {toxworkdir}
555+
commands = '{envpython}' '{toxworkdir}'/'foo bar'
556556
""",
557557
)
558558

@@ -567,7 +567,7 @@ def test_command_substitution_whitespace(self, tmpdir, newconfig):
567567

568568
assert envconfig.commands[0] == [
569569
str(envconfig.envbindir.join("python")),
570-
str(config.toxworkdir.realpath()),
570+
str(config.toxworkdir.realpath().join("foo bar")),
571571
]
572572

573573

0 commit comments

Comments
 (0)