Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 097b365

Browse files
committed
Merge pull request #192 from pre-commit/quote_params
Quote args in venv'd languages
2 parents 9fc6a8b + f4d251f commit 097b365

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

pre_commit/languages/helpers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
from __future__ import unicode_literals
22

3+
import pipes
4+
35

46
def file_args_to_stdin(file_args):
57
return '\0'.join(list(file_args) + [''])
68

79

810
def run_hook(env, hook, file_args):
11+
quoted_args = [pipes.quote(arg) for arg in hook['args']]
912
return env.run(
10-
' '.join(['xargs', '-0', hook['entry']] + hook['args']),
13+
' '.join(['xargs', '-0', hook['entry']] + quoted_args),
1114
stdin=file_args_to_stdin(file_args),
1215
retcode=None,
1316
)

requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
-e .
22

3+
astroid<1.3.3
34
coverage
45
flake8
56
mock

tests/repository_test.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ def _test_hook_repo(
2727
args,
2828
expected,
2929
expected_return_code=0,
30+
config_kwargs=None
3031
):
3132
path = make_repo(tmpdir_factory, repo_path)
32-
config = make_config_from_repo(path)
33+
config = make_config_from_repo(path, **(config_kwargs or {}))
3334
repo = Repository.create(config, store)
3435
hook_dict = [
3536
hook for repo_hook_id, hook in repo.hooks if repo_hook_id == hook_id
@@ -47,6 +48,23 @@ def test_python_hook(tmpdir_factory, store):
4748
)
4849

4950

51+
@pytest.mark.integration
52+
def test_python_hook_args_with_spaces(tmpdir_factory, store):
53+
_test_hook_repo(
54+
tmpdir_factory, store, 'python_hooks_repo',
55+
'foo',
56+
[],
57+
"['i have spaces', 'and\"\\'quotes', '$and !this']\n"
58+
'Hello World\n',
59+
config_kwargs={
60+
'hooks': [{
61+
'id': 'foo',
62+
'args': ['i have spaces', 'and"\'quotes', '$and !this'],
63+
}]
64+
},
65+
)
66+
67+
5068
@pytest.mark.integration
5169
def test_versioned_python_hook(tmpdir_factory, store):
5270
_test_hook_repo(

0 commit comments

Comments
 (0)