Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d65c43b

Browse filesBrowse files
committed
feature #26372 Revert "feature #24763 [Process] Allow writing portable "prepared" command lines (Simperfit)" (nicolas-grekas)
This PR was merged into the 4.1-dev branch. Discussion ---------- Revert "feature #24763 [Process] Allow writing portable "prepared" command lines (Simperfit)" | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - This reverts commit 1364089, reversing changes made to e043478. As discussed in #24763 and #26344 This doens't revert the possibility to use prepared command lines. They just won't be *portable* anymore, unless special care is taken by "userland". Ie the placeholders need to be shell-dependent: use eg `echo "$FOO"` on *nix (the double quotes *are* important), and `echo !FOO!` on Windows (no double quotes there). Commits ------- 6a98bfa Revert "feature #24763 [Process] Allow writing portable "prepared" command lines (Simperfit)"
2 parents 7a9929f + 6a98bfa commit d65c43b
Copy full SHA for d65c43b

File tree

2 files changed

+3
-57
lines changed
Filter options

2 files changed

+3
-57
lines changed

‎src/Symfony/Component/Process/Process.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Process/Process.php
+3-29Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -258,21 +258,18 @@ public function start(callable $callback = null, array $env = array())
258258
$this->hasCallback = null !== $callback;
259259
$descriptors = $this->getDescriptors();
260260

261-
if ($this->env) {
262-
$env += $this->env;
263-
}
264-
265261
if (is_array($commandline = $this->commandline)) {
266262
$commandline = implode(' ', array_map(array($this, 'escapeArgument'), $commandline));
267263

268264
if ('\\' !== DIRECTORY_SEPARATOR) {
269265
// exec is mandatory to deal with sending a signal to the process
270266
$commandline = 'exec '.$commandline;
271267
}
272-
} else {
273-
$commandline = $this->replacePlaceholders($commandline, $env);
274268
}
275269

270+
if ($this->env) {
271+
$env += $this->env;
272+
}
276273
$env += $this->getDefaultEnv();
277274

278275
$options = array('suppress_errors' => true);
@@ -1552,29 +1549,6 @@ private function escapeArgument(string $argument): string
15521549
return '"'.str_replace(array('"', '^', '%', '!', "\n"), array('""', '"^^"', '"^%"', '"^!"', '!LF!'), $argument).'"';
15531550
}
15541551

1555-
private function replacePlaceholders(string $commandline, array $env)
1556-
{
1557-
$pattern = '\\' === DIRECTORY_SEPARATOR ? '!%s!' : '"$%s"';
1558-
1559-
return preg_replace_callback('/\{\{ ?([_a-zA-Z0-9]++) ?\}\}/', function ($m) use ($pattern, $commandline, $env) {
1560-
if (!isset($env[$m[1]]) || false === $env[$m[1]]) {
1561-
foreach ($env as $k => $v) {
1562-
if (false === $v) {
1563-
unset($env[$k]);
1564-
}
1565-
}
1566-
if (!$env) {
1567-
throw new InvalidArgumentException(sprintf('Invalid command line "%s": no values provided for any placeholders.', $commandline));
1568-
}
1569-
$env = implode('", "', array_keys($env));
1570-
1571-
throw new InvalidArgumentException(sprintf('Invalid command line "%s": no value provided for placeholder "%s", did you mean "%s"?', $commandline, $m[1], $env));
1572-
}
1573-
1574-
return sprintf($pattern, $m[1]);
1575-
}, $commandline);
1576-
}
1577-
15781552
private function getDefaultEnv()
15791553
{
15801554
$env = array();

‎src/Symfony/Component/Process/Tests/ProcessTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Process/Tests/ProcessTest.php
-28Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,34 +1474,6 @@ public function provideEscapeArgument()
14741474
yield array('éÉèÈàÀöä');
14751475
}
14761476

1477-
public function testPreparedCommand()
1478-
{
1479-
$p = new Process(self::$phpBin.' -r \'print_r($argv);\' {{ abc }}DEF');
1480-
$p->run(null, array('abc' => 'A" B "C'));
1481-
1482-
$this->assertContains('A" B "CDEF', $p->getOutput());
1483-
}
1484-
1485-
/**
1486-
* @expectedException \Symfony\Component\Process\Exception\InvalidArgumentException
1487-
* @expectedExceptionMessage Invalid command line "echo {{ abc }}": no value provided for placeholder "abc", did you mean "bcd"?
1488-
*/
1489-
public function testPreparedCommandWithMissingValue()
1490-
{
1491-
$p = new Process('echo {{ abc }}');
1492-
$p->run(null, array('bcd' => 'BCD'));
1493-
}
1494-
1495-
/**
1496-
* @expectedException \Symfony\Component\Process\Exception\InvalidArgumentException
1497-
* @expectedExceptionMessage Invalid command line "echo {{ abc }}": no values provided for any placeholders.
1498-
*/
1499-
public function testPreparedCommandWithNoValues()
1500-
{
1501-
$p = new Process('echo {{ abc }}');
1502-
$p->run();
1503-
}
1504-
15051477
public function testEnvArgument()
15061478
{
15071479
$env = array('FOO' => 'Foo', 'BAR' => 'Bar');

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.