From 46cf1b6edb463c9eea5dd675ec092c2e8409039d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Mart=C3=ADnez?= Date: Fri, 20 Oct 2017 19:58:11 +0200 Subject: [PATCH 1/3] Fix duplicated crontab 2>&1 expression --- .../Framework/Shell/CommandRenderer.php | 10 +++--- .../Shell/Test/Unit/CommandRendererTest.php | 36 +++++++++++++++---- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/lib/internal/Magento/Framework/Shell/CommandRenderer.php b/lib/internal/Magento/Framework/Shell/CommandRenderer.php index 0c5393e11ed35..6cf91d09479e1 100644 --- a/lib/internal/Magento/Framework/Shell/CommandRenderer.php +++ b/lib/internal/Magento/Framework/Shell/CommandRenderer.php @@ -1,6 +1,6 @@ &1)*(\s*\|)|$/', ' 2>&1$2', $command); $arguments = array_map('escapeshellarg', $arguments); - $command = preg_replace('/\s?\||$/', ' 2>&1$0', $command); - $command = vsprintf($command, $arguments); - return $command; + if (empty($arguments)) { + return $command; + } + return vsprintf($command, $arguments); } } diff --git a/lib/internal/Magento/Framework/Shell/Test/Unit/CommandRendererTest.php b/lib/internal/Magento/Framework/Shell/Test/Unit/CommandRendererTest.php index 2ac94f42971e7..79c06abce30a8 100644 --- a/lib/internal/Magento/Framework/Shell/Test/Unit/CommandRendererTest.php +++ b/lib/internal/Magento/Framework/Shell/Test/Unit/CommandRendererTest.php @@ -1,22 +1,44 @@ assertEquals( - "php -r " . escapeshellarg($testArgument) . " 2>&1 | grep " . escapeshellarg($testArgument2) . " 2>&1", - $commandRenderer->render('php -r %s | grep %s', [$testArgument, $testArgument2]) + $expectedCommand, + $commandRenderer->render($actualCommand, $testArguments) ); } + + public function commandsDataProvider() + { + $testArgument = 'argument'; + $testArgument2 = 'argument2'; + + $expectedCommand = "php -r %s 2>&1 | grep %s 2>&1"; + $expectedCommandArgs = "php -r '" . $testArgument . "' 2>&1 | grep '" . $testArgument2 . "' 2>&1"; + + return [ + [$expectedCommand, 'php -r %s | grep %s', []], + [$expectedCommand, 'php -r %s 2>&1 | grep %s', []], + [$expectedCommand, 'php -r %s 2>&1 2>&1 | grep %s', []], + [$expectedCommandArgs, 'php -r %s | grep %s', [$testArgument, $testArgument2]], + [$expectedCommandArgs, 'php -r %s 2>&1 | grep %s', [$testArgument, $testArgument2]], + [$expectedCommandArgs, 'php -r %s 2>&1 2>&1 | grep %s', [$testArgument, $testArgument2]], + ]; + } } From dde32da2f60cf424a4444882eb21d03d5c465259 Mon Sep 17 00:00:00 2001 From: Vlad Veselov Date: Wed, 25 Oct 2017 23:54:41 +0300 Subject: [PATCH 2/3] Update CommandRenderer.php --- lib/internal/Magento/Framework/Shell/CommandRenderer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Shell/CommandRenderer.php b/lib/internal/Magento/Framework/Shell/CommandRenderer.php index 6cf91d09479e1..5603e223ea8e4 100644 --- a/lib/internal/Magento/Framework/Shell/CommandRenderer.php +++ b/lib/internal/Magento/Framework/Shell/CommandRenderer.php @@ -1,6 +1,6 @@ Date: Wed, 25 Oct 2017 23:55:00 +0300 Subject: [PATCH 3/3] Update CommandRendererTest.php --- .../Magento/Framework/Shell/Test/Unit/CommandRendererTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Shell/Test/Unit/CommandRendererTest.php b/lib/internal/Magento/Framework/Shell/Test/Unit/CommandRendererTest.php index 79c06abce30a8..48bf32b5cf995 100644 --- a/lib/internal/Magento/Framework/Shell/Test/Unit/CommandRendererTest.php +++ b/lib/internal/Magento/Framework/Shell/Test/Unit/CommandRendererTest.php @@ -1,6 +1,6 @@