Skip to content

Commit f7459ab

Browse files
committed
MAGETWO-82462: [Backport 2.1-develop] #11586 Fix duplicated crontab 2>&1 expression #11590
- Merge Pull Request #11590 from adrian-martinez-interactiv4/magento2:FR21#CRON-INSTALL-PARSE-STDERR - Merged commits: 1. 46cf1b6 2. dde32da 3. 4478cf4
2 parents 05bb680 + 4478cf4 commit f7459ab

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

lib/internal/Magento/Framework/Shell/CommandRenderer.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ class CommandRenderer implements CommandRendererInterface
1616
*/
1717
public function render($command, array $arguments = [])
1818
{
19+
$command = preg_replace('/(\s+2>&1)*(\s*\|)|$/', ' 2>&1$2', $command);
1920
$arguments = array_map('escapeshellarg', $arguments);
20-
$command = preg_replace('/\s?\||$/', ' 2>&1$0', $command);
21-
$command = vsprintf($command, $arguments);
22-
return $command;
21+
if (empty($arguments)) {
22+
return $command;
23+
}
24+
return vsprintf($command, $arguments);
2325
}
2426
}

lib/internal/Magento/Framework/Shell/Test/Unit/CommandRendererTest.php

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,40 @@
55
*/
66
namespace Magento\Framework\Shell\Test\Unit;
77

8-
use \Magento\Framework\Shell\CommandRenderer;
8+
use Magento\Framework\Shell\CommandRenderer;
99

1010
class CommandRendererTest extends \PHPUnit_Framework_TestCase
1111
{
12-
public function testRender()
12+
/**
13+
* @param $expectedCommand
14+
* @param $actualCommand
15+
* @param $testArguments
16+
* @dataProvider commandsDataProvider
17+
*/
18+
public function testRender($expectedCommand, $actualCommand, $testArguments)
1319
{
14-
$testArgument = 'argument';
15-
$testArgument2 = 'argument2';
1620
$commandRenderer = new CommandRenderer();
1721
$this->assertEquals(
18-
"php -r " . escapeshellarg($testArgument) . " 2>&1 | grep " . escapeshellarg($testArgument2) . " 2>&1",
19-
$commandRenderer->render('php -r %s | grep %s', [$testArgument, $testArgument2])
22+
$expectedCommand,
23+
$commandRenderer->render($actualCommand, $testArguments)
2024
);
2125
}
26+
27+
public function commandsDataProvider()
28+
{
29+
$testArgument = 'argument';
30+
$testArgument2 = 'argument2';
31+
32+
$expectedCommand = "php -r %s 2>&1 | grep %s 2>&1";
33+
$expectedCommandArgs = "php -r '" . $testArgument . "' 2>&1 | grep '" . $testArgument2 . "' 2>&1";
34+
35+
return [
36+
[$expectedCommand, 'php -r %s | grep %s', []],
37+
[$expectedCommand, 'php -r %s 2>&1 | grep %s', []],
38+
[$expectedCommand, 'php -r %s 2>&1 2>&1 | grep %s', []],
39+
[$expectedCommandArgs, 'php -r %s | grep %s', [$testArgument, $testArgument2]],
40+
[$expectedCommandArgs, 'php -r %s 2>&1 | grep %s', [$testArgument, $testArgument2]],
41+
[$expectedCommandArgs, 'php -r %s 2>&1 2>&1 | grep %s', [$testArgument, $testArgument2]],
42+
];
43+
}
2244
}

0 commit comments

Comments
 (0)