There was an error while loading. Please reload this page.
1 parent 9fc6a8b commit f4d251fCopy full SHA for f4d251f
3 files changed
pre_commit/languages/helpers.py
@@ -1,13 +1,16 @@
1
from __future__ import unicode_literals
2
3
+import pipes
4
+
5
6
def file_args_to_stdin(file_args):
7
return '\0'.join(list(file_args) + [''])
8
9
10
def run_hook(env, hook, file_args):
11
+ quoted_args = [pipes.quote(arg) for arg in hook['args']]
12
return env.run(
- ' '.join(['xargs', '-0', hook['entry']] + hook['args']),
13
+ ' '.join(['xargs', '-0', hook['entry']] + quoted_args),
14
stdin=file_args_to_stdin(file_args),
15
retcode=None,
16
)
requirements-dev.txt
@@ -1,5 +1,6 @@
-e .
+astroid<1.3.3
coverage
flake8
mock
tests/repository_test.py
@@ -27,9 +27,10 @@ def _test_hook_repo(
27
args,
28
expected,
29
expected_return_code=0,
30
+ config_kwargs=None
31
):
32
path = make_repo(tmpdir_factory, repo_path)
- config = make_config_from_repo(path)
33
+ config = make_config_from_repo(path, **(config_kwargs or {}))
34
repo = Repository.create(config, store)
35
hook_dict = [
36
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):
47
48
49
50
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
68
@pytest.mark.integration
69
def test_versioned_python_hook(tmpdir_factory, store):
70
_test_hook_repo(
0 commit comments