Skip to content

Commit 97d92b2

Browse files
committed
Ensure filenames are correctly quoted in sed commands.
1 parent 1362694 commit 97d92b2

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

pyinfra/operations/util/files.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from datetime import datetime
44

5-
from pyinfra.api import StringCommand
5+
from pyinfra.api import QuoteString, StringCommand
66

77

88
def ensure_mode_int(mode):
@@ -64,11 +64,13 @@ def sed_replace(
6464

6565
sed_script = sed_script_formatter.format(line, replace, flags)
6666

67-
sed_command = StringCommand('sed', '-i.{0}'.format(backup_extension), sed_script, filename)
67+
sed_command = StringCommand(
68+
'sed', '-i.{0}'.format(backup_extension), sed_script, QuoteString(filename),
69+
)
6870

6971
if not backup: # if we're not backing up, remove the file *if* sed succeeds
7072
backup_filename = '{0}.{1}'.format(filename, backup_extension)
71-
sed_command = StringCommand(sed_command, '&&', 'rm', '-f', backup_filename)
73+
sed_command = StringCommand(sed_command, '&&', 'rm', '-f', QuoteString(backup_filename))
7274

7375
return sed_command
7476

0 commit comments

Comments
 (0)