diff options
author | David Stanek <dstanek@dstanek.com> | 2015-10-05 18:23:35 +0000 |
---|---|---|
committer | David Stanek <dstanek@dstanek.com> | 2015-10-05 18:23:35 +0000 |
commit | f8b7e6cce49c012885f9d15e05751c8dc85359e7 (patch) | |
tree | 967717040a1c9524bf367528e17600819e9eef5e | |
parent | 260c83e398490f63791535b5df8b47d72b2ef42c (diff) | |
download | tox-f8b7e6cce49c012885f9d15e05751c8dc85359e7.tar.gz |
Fixes bug 181; allow # in commandsbug_181
If a # was in a command the original code naively removed it and
everything after assuming it was a comment. This meant that a #
could not be used in a command even if it was quoted or escaped.
This fix is backward incompatible because it no longer allows a
comment to appear after a line escape (\). I think is is acceptable
because in most other environments a backslash would preceed a
newline to escape it and tell the interpreter to ignore it. This
brings tox's command behavior more in line with what Unix shells
or Python actually do.
-rw-r--r-- | tests/test_config.py | 28 | ||||
-rw-r--r-- | tox/config.py | 4 |
2 files changed, 24 insertions, 8 deletions
diff --git a/tests/test_config.py b/tests/test_config.py index 4bdba50..c35195b 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -417,7 +417,7 @@ class TestIniParser: config = newconfig(""" [section] key2= - cmd1 {item1} \ # a comment + cmd1 {item1} \ {item2} """) reader = SectionReader("section", config._cfg) @@ -432,12 +432,32 @@ class TestIniParser: config = newconfig(""" [section] key1= - cmd1 'with space' \ # a comment - 'after the comment' + cmd1 'part one' \ + 'part two' """) reader = SectionReader("section", config._cfg) x = reader.getargvlist("key1") - assert x == [["cmd1", "with space", "after the comment"]] + assert x == [["cmd1", "part one", "part two"]] + + def test_argvlist_comment_after_command(self, tmpdir, newconfig): + config = newconfig(""" + [section] + key1= + cmd1 --flag # run the flag on the command + """) + reader = SectionReader("section", config._cfg) + x = reader.getargvlist("key1") + assert x == [["cmd1", "--flag"]] + + def test_argvlist_command_contains_hash(self, tmpdir, newconfig): + config = newconfig(""" + [section] + key1= + cmd1 --re "use the # symbol for an arg" + """) + reader = SectionReader("section", config._cfg) + x = reader.getargvlist("key1") + assert x == [["cmd1", "--re", "use the # symbol for an arg"]] def test_argvlist_positional_substitution(self, tmpdir, newconfig): config = newconfig(""" diff --git a/tox/config.py b/tox/config.py index d68d276..85f4650 100644 --- a/tox/config.py +++ b/tox/config.py @@ -999,9 +999,6 @@ class _ArgvlistReader: current_command = "" for line in value.splitlines(): line = line.rstrip() - i = line.find("#") - if i != -1: - line = line[:i].rstrip() if not line: continue if line.endswith("\\"): @@ -1053,7 +1050,6 @@ class _ArgvlistReader: shlexer = shlex.shlex(newcommand, posix=True) shlexer.whitespace_split = True shlexer.escape = '' - shlexer.commenters = '' argv = list(shlexer) return argv |