From a3c4eb4a7c0f5128948e7346e900a5d79d85ecb0 Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Thu, 3 Apr 2014 15:45:55 -0700 Subject: Allow backslashing curly braces to prevent expansion e.g.: commands=echo \{posargs\} = {posargs} --- tox/_config.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tox/_config.py b/tox/_config.py index 6006fa9..4d54924 100644 --- a/tox/_config.py +++ b/tox/_config.py @@ -451,8 +451,8 @@ class IndexServerConfig: self.url = url RE_ITEM_REF = re.compile( - ''' - [{] + r''' + (?[^[:{}]+):)? # optional sub_type for special rules (?P[^{}]*) # substitution key [}] @@ -686,7 +686,7 @@ class CommandParser(object): def word_has_ended(): return ((cur_char in string.whitespace and ps.word and ps.word[-1] not in string.whitespace) or - (cur_char == '{' and ps.depth == 0) or + (cur_char == '{' and ps.depth == 0 and not ps.word.endswith('\\')) or (ps.depth == 0 and ps.word and ps.word[-1] == '}') or (cur_char not in string.whitespace and ps.word and ps.word.strip() == '')) -- cgit v1.2.1 From d37e3d69bf0496828eaf140f16d53db5ae9c8c80 Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Sun, 11 May 2014 22:44:09 -0700 Subject: Add test_posargs_backslashed_or_quoted --- tests/test_config.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/test_config.py b/tests/test_config.py index b8d0aa3..c4ec9cc 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -663,6 +663,23 @@ class TestConfigTestEnv: assert argv[0] == ["cmd1", "[hello]", "world"] assert argv[1] == ["cmd1", "brave", "new", "world"] + def test_posargs_backslashed_or_quoted(self, tmpdir, newconfig): + inisource = """ + [testenv:py24] + commands = + echo "\{posargs\}" = {posargs} + echo "posargs = " "{posargs}" + """ + conf = newconfig([], inisource).envconfigs['py24'] + argv = conf.commands + assert argv[0] == ['echo', '\\{posargs\\}', '='] + assert argv[1] == ['echo', 'posargs ='] + + conf = newconfig(['dog', 'cat'], inisource).envconfigs['py24'] + argv = conf.commands + assert argv[0] == ['echo', '\\{posargs\\}', '=', 'dog', 'cat'] + assert argv[1] == ['echo', 'posargs =', 'dog', 'cat'] + def test_rewrite_posargs(self, tmpdir, newconfig): inisource = """ [testenv:py24] -- cgit v1.2.1