Skip to content

Commit 788d5ed

Browse files
author
Oleksii Korshenko
authored
MAGETWO-82461: #11586 Fix duplicated crontab 2>&1 expression #11587
2 parents a180561 + 72bb121 commit 788d5ed

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ 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);
2121
if (empty($arguments)) {
2222
return $command;
2323
}

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

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +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
}
2226

23-
public function testRenderWithoutArguments()
27+
public function commandsDataProvider()
2428
{
25-
$commandRenderer = new CommandRenderer();
26-
$this->assertEquals(
27-
"php -r %s 2>&1 | grep %s 2>&1",
28-
$commandRenderer->render('php -r %s | grep %s', [])
29-
);
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+
];
3043
}
3144
}

0 commit comments

Comments
 (0)