Skip to content

Commit 84c12f7

Browse files
committed
Replace escapeshellarg with quote across the codebase
1 parent 590d8da commit 84c12f7

File tree

11 files changed

+22
-22
lines changed

11 files changed

+22
-22
lines changed

contrib/crontab.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
namespace Deployer;
2626

27-
use function Deployer\Support\escape_shell_argument;
2827

2928
// Get path to bin
3029
set('bin/crontab', function () {
@@ -137,7 +136,7 @@ function setRemoteCrontab(array $lines): void
137136
}
138137

139138
foreach ($lines as $line) {
140-
run("echo " . escape_shell_argument($line) . " >> $tmpCrontabPath");
139+
run("echo " . quote($line) . " >> $tmpCrontabPath");
141140
}
142141

143142
run("$sudo {{bin/crontab}} " . $tmpCrontabPath);

contrib/rsync.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@
141141
$excludeFile = $config['exclude-file'];
142142
$excludesRsync = '';
143143
foreach ($excludes as $exclude) {
144-
$excludesRsync .= ' --exclude=' . escapeshellarg($exclude);
144+
$excludesRsync .= ' --exclude=' . quote($exclude);
145145
}
146146
if (!empty($excludeFile) && file_exists($excludeFile) && is_file($excludeFile) && is_readable($excludeFile)) {
147-
$excludesRsync .= ' --exclude-from=' . escapeshellarg($excludeFile);
147+
$excludesRsync .= ' --exclude-from=' . quote($excludeFile);
148148
}
149149

150150
return $excludesRsync;
@@ -156,10 +156,10 @@
156156
$includeFile = $config['include-file'];
157157
$includesRsync = '';
158158
foreach ($includes as $include) {
159-
$includesRsync .= ' --include=' . escapeshellarg($include);
159+
$includesRsync .= ' --include=' . quote($include);
160160
}
161161
if (!empty($includeFile) && file_exists($includeFile) && is_file($includeFile) && is_readable($includeFile)) {
162-
$includesRsync .= ' --include-from=' . escapeshellarg($includeFile);
162+
$includesRsync .= ' --include-from=' . quote($includeFile);
163163
}
164164

165165
return $includesRsync;

recipe/deploy/lock.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
desc('Locks deploy');
88
task('deploy:lock', function () {
9-
$user = escapeshellarg(get('user'));
9+
$user = quote(get('user'));
1010
$locked = run("[ -f {{deploy_path}}/.dep/deploy.lock ] && echo +locked || echo $user > {{deploy_path}}/.dep/deploy.lock");
1111
if ($locked === '+locked') {
1212
$lockedUser = run("cat {{deploy_path}}/.dep/deploy.lock");

recipe/deploy/release.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Deployer\Exception\Exception;
66
use Symfony\Component\Console\Helper\Table;
77

8-
use function Deployer\Support\escape_shell_argument;
98

109
// The name of the release.
1110
set('release_name', function () {
@@ -126,7 +125,7 @@
126125
];
127126

128127
// Save metainfo about release.
129-
$json = escape_shell_argument(json_encode($metainfo));
128+
$json = quote(json_encode($metainfo));
130129
run("echo $json >> .dep/releases_log");
131130

132131
// Make new release.

recipe/deploy/update_code.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@
8282

8383
if ($strategy === 'local_archive') {
8484
$gitRoot = runLocally("$git rev-parse --show-toplevel");
85-
runLocally("$git -C " . escapeshellarg($gitRoot) . " archive $targetWithDir -o archive.tar");
85+
runLocally("$git -C " . quote($gitRoot) . " archive $targetWithDir -o archive.tar");
8686
upload("$gitRoot/archive.tar", '{{release_path}}/archive.tar');
8787
run("tar -xf {{release_path}}/archive.tar -C {{release_path}}");
8888
run("rm {{release_path}}/archive.tar");
8989
unlink("$gitRoot/archive.tar");
9090

91-
$rev = escapeshellarg(runLocally("git rev-list $target -1"));
91+
$rev = quote(runLocally("git rev-list $target -1"));
9292
} else {
9393
$repository = get('repository');
9494

@@ -130,7 +130,7 @@
130130
throw new ConfigurationException(parse("Unknown `update_code_strategy` option: {{update_code_strategy}}."));
131131
}
132132

133-
$rev = escapeshellarg(run("$git rev-list $target -1"));
133+
$rev = quote(run("$git rev-list $target -1"));
134134
}
135135

136136
// Save git revision in REVISION file.

recipe/provision/nodejs.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Deployer;
44

5-
use function Deployer\Support\escape_shell_argument;
65

76
set('node_version', '--lts');
87

@@ -33,6 +32,6 @@
3332
run('chmod +x /usr/local/bin/fnm');
3433

3534
run('fnm install {{node_version}}');
36-
run("echo " . escape_shell_argument('eval "`fnm env`"') . " >> /etc/profile.d/fnm.sh");
35+
run("echo " . quote('eval "`fnm env`"') . " >> /etc/profile.d/fnm.sh");
3736
})
3837
->oncePerNode();

src/Host/Host.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ public function connectionString(): string
288288

289289
public function connectionOptionsString(): string
290290
{
291-
return implode(' ', array_map('escapeshellarg', $this->connectionOptionsArray()));
291+
return implode(' ', array_map('Deployer\quote', $this->connectionOptionsArray()));
292292
}
293293

294294
/**

src/Ssh/SshClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function run(Host $host, string $command, RunParams $params): string
4646
if ($this->output->isDebug()) {
4747
$sshString = $ssh[0];
4848
for ($i = 1; $i < count($ssh); $i++) {
49-
$sshString .= ' ' . escapeshellarg((string) $ssh[$i]);
49+
$sshString .= ' ' . \Deployer\quote((string) $ssh[$i]);
5050
}
5151
$this->output->writeln("[$host] $sshString");
5252
}

src/Support/helpers.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
namespace Deployer\Support;
1212

13+
use function Deployer\quote;
14+
1315
function array_flatten(array $array): array
1416
{
1517
$flatten = [];
@@ -58,7 +60,7 @@ function env_stringify(array $array): string
5860
{
5961
return implode(' ', array_map(
6062
function ($key, $value) {
61-
return sprintf("%s=%s", $key, escapeshellarg((string) $value));
63+
return sprintf("%s=%s", $key, quote((string) $value));
6264
},
6365
array_keys($array),
6466
$array,

src/Utility/Rsync.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Process\Exception\ProcessFailedException;
1919
use Symfony\Component\Process\Process;
2020

21+
use function Deployer\quote;
2122
use function Deployer\writeln;
2223

2324
class Rsync
@@ -76,7 +77,7 @@ function (string $value) {
7677

7778
$commandString = $command[0];
7879
for ($i = 1; $i < count($command); $i++) {
79-
$commandString .= ' ' . escapeshellarg($command[$i]);
80+
$commandString .= ' ' . quote($command[$i]);
8081
}
8182
if ($this->output->isVerbose()) {
8283
$this->output->writeln("[$host] $commandString");

0 commit comments

Comments
 (0)