Properly quote patterns before passing to grap in `find_in_file` fact.
@@ -2,6 +2,8 @@ from __future__ import unicode_literals
import re
+from six.moves import shlex_quote
+
from pyinfra.api.facts import FactBase
from .util.files import parse_ls_output
@@ -63,8 +65,10 @@ class FindInFile(FactBase):
def command(self, name, pattern):
self.name = name
+ pattern = shlex_quote(pattern)
+
return (
- 'grep "{0}" {1} 2> /dev/null || '
+ 'grep {0} {1} 2> /dev/null || '
'(find {1} -type f > /dev/null && echo "__pyinfra_exists_{1}")'
).format(pattern, name).strip()
