From bf24ed71e472387b5866dbc7ae5916217342eb5a Mon Sep 17 00:00:00 2001 From: llaakkkk Date: Wed, 7 Mar 2018 10:26:08 +0100 Subject: [PATCH 01/12] Added check escapeshellarg with data --- src/Formatter/CurlCommandFormatter.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Formatter/CurlCommandFormatter.php b/src/Formatter/CurlCommandFormatter.php index 5cdd427..8a8225c 100644 --- a/src/Formatter/CurlCommandFormatter.php +++ b/src/Formatter/CurlCommandFormatter.php @@ -3,12 +3,13 @@ namespace Http\Message\Formatter; use Http\Message\Formatter; +use PhpSpec\Exception\Exception; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; +use Http\Message\Exception\EmptyStringException; /** * A formatter that prints a cURL command for HTTP requests. - * * @author Tobias Nyholm */ class CurlCommandFormatter implements Formatter @@ -18,7 +19,7 @@ class CurlCommandFormatter implements Formatter */ public function formatRequest(RequestInterface $request) { - $command = sprintf('curl %s', escapeshellarg((string) $request->getUri()->withFragment(''))); + $command = sprintf('curl %s', escapeshellarg((string)$request->getUri()->withFragment(''))); if ('1.0' === $request->getProtocolVersion()) { $command .= ' --http1.0'; } elseif ('2.0' === $request->getProtocolVersion()) { @@ -29,7 +30,7 @@ public function formatRequest(RequestInterface $request) if ('HEAD' === $method) { $command .= ' --head'; } elseif ('GET' !== $method) { - $command .= ' --request '.$method; + $command .= ' --request ' . $method; } $command .= $this->getHeadersAsCommandOptions($request); @@ -45,7 +46,13 @@ public function formatRequest(RequestInterface $request) } else { $data = '[non-seekable stream omitted]'; } - $command .= sprintf(' --data %s', escapeshellarg($data)); + + $escapedData = @escapeshellarg($data); + if (isset($php_errormsg)) { + throw new \InvalidArgumentException($php_errormsg); + } + $command .= sprintf(' --data %s', $escapedData); + } return $command; @@ -78,7 +85,7 @@ private function getHeadersAsCommandOptions(RequestInterface $request) continue; } - $command .= sprintf(' -H %s', escapeshellarg($name.': '.$request->getHeaderLine($name))); + $command .= sprintf(' -H %s', escapeshellarg($name . ': ' . $request->getHeaderLine($name))); } return $command; From ad715e4fb388fb1a09d037f4d73bf89a03ca0a3d Mon Sep 17 00:00:00 2001 From: llaakkkk Date: Wed, 7 Mar 2018 10:26:08 +0100 Subject: [PATCH 02/12] Added check escapeshellarg with data From 05707e8382853da57b6f4b9113b20aeea6737cef Mon Sep 17 00:00:00 2001 From: llaakkkk Date: Wed, 7 Mar 2018 10:45:06 +0100 Subject: [PATCH 03/12] Fixed uses --- src/Formatter/CurlCommandFormatter.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Formatter/CurlCommandFormatter.php b/src/Formatter/CurlCommandFormatter.php index 8a8225c..f74d7bf 100644 --- a/src/Formatter/CurlCommandFormatter.php +++ b/src/Formatter/CurlCommandFormatter.php @@ -3,10 +3,8 @@ namespace Http\Message\Formatter; use Http\Message\Formatter; -use PhpSpec\Exception\Exception; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; -use Http\Message\Exception\EmptyStringException; /** * A formatter that prints a cURL command for HTTP requests. From 4277f6ea9e4a3bae717f7d5506874e4ce04d238b Mon Sep 17 00:00:00 2001 From: llaakkkk Date: Wed, 7 Mar 2018 10:49:49 +0100 Subject: [PATCH 04/12] Fixed code format --- src/Formatter/CurlCommandFormatter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Formatter/CurlCommandFormatter.php b/src/Formatter/CurlCommandFormatter.php index f74d7bf..b8c325c 100644 --- a/src/Formatter/CurlCommandFormatter.php +++ b/src/Formatter/CurlCommandFormatter.php @@ -28,7 +28,7 @@ public function formatRequest(RequestInterface $request) if ('HEAD' === $method) { $command .= ' --head'; } elseif ('GET' !== $method) { - $command .= ' --request ' . $method; + $command .= ' --request '.$method; } $command .= $this->getHeadersAsCommandOptions($request); @@ -83,7 +83,7 @@ private function getHeadersAsCommandOptions(RequestInterface $request) continue; } - $command .= sprintf(' -H %s', escapeshellarg($name . ': ' . $request->getHeaderLine($name))); + $command .= sprintf(' -H %s', escapeshellarg($name.': '.$request->getHeaderLine($name))); } return $command; From 1fea056041e36777778fb0e7925a08af07c3ba30 Mon Sep 17 00:00:00 2001 From: llaakkkk Date: Wed, 7 Mar 2018 11:00:03 +0100 Subject: [PATCH 05/12] Fixed code format --- src/Formatter/CurlCommandFormatter.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Formatter/CurlCommandFormatter.php b/src/Formatter/CurlCommandFormatter.php index b8c325c..f0604d9 100644 --- a/src/Formatter/CurlCommandFormatter.php +++ b/src/Formatter/CurlCommandFormatter.php @@ -8,6 +8,7 @@ /** * A formatter that prints a cURL command for HTTP requests. + * * @author Tobias Nyholm */ class CurlCommandFormatter implements Formatter @@ -17,7 +18,7 @@ class CurlCommandFormatter implements Formatter */ public function formatRequest(RequestInterface $request) { - $command = sprintf('curl %s', escapeshellarg((string)$request->getUri()->withFragment(''))); + $command = sprintf('curl %s', escapeshellarg((string) $request->getUri()->withFragment(''))); if ('1.0' === $request->getProtocolVersion()) { $command .= ' --http1.0'; } elseif ('2.0' === $request->getProtocolVersion()) { From 47585f00957afbc526d07a7505ada95296e5f82b Mon Sep 17 00:00:00 2001 From: llaakkkk Date: Wed, 7 Mar 2018 11:02:52 +0100 Subject: [PATCH 06/12] Fixed code format --- src/Formatter/CurlCommandFormatter.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Formatter/CurlCommandFormatter.php b/src/Formatter/CurlCommandFormatter.php index f0604d9..02a33e5 100644 --- a/src/Formatter/CurlCommandFormatter.php +++ b/src/Formatter/CurlCommandFormatter.php @@ -51,7 +51,6 @@ public function formatRequest(RequestInterface $request) throw new \InvalidArgumentException($php_errormsg); } $command .= sprintf(' --data %s', $escapedData); - } return $command; From 4e8b8ce69a2762b618e34163cd5a44f1629227df Mon Sep 17 00:00:00 2001 From: llaakkkk Date: Wed, 7 Mar 2018 11:39:29 +0100 Subject: [PATCH 07/12] Added die when escapeshallarg failed --- src/Formatter/CurlCommandFormatter.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Formatter/CurlCommandFormatter.php b/src/Formatter/CurlCommandFormatter.php index 02a33e5..f00a5af 100644 --- a/src/Formatter/CurlCommandFormatter.php +++ b/src/Formatter/CurlCommandFormatter.php @@ -46,10 +46,9 @@ public function formatRequest(RequestInterface $request) $data = '[non-seekable stream omitted]'; } - $escapedData = @escapeshellarg($data); - if (isset($php_errormsg)) { - throw new \InvalidArgumentException($php_errormsg); - } + $escapedData = @escapeshellarg($data) or + die ("We couldn't not escape the data properly: error was '$php_errormsg'"); + $command .= sprintf(' --data %s', $escapedData); } From 15fa06245691a997317141af19da0df7bf12598b Mon Sep 17 00:00:00 2001 From: llaakkkk Date: Wed, 7 Mar 2018 11:40:41 +0100 Subject: [PATCH 08/12] Fixed code format --- src/Formatter/CurlCommandFormatter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Formatter/CurlCommandFormatter.php b/src/Formatter/CurlCommandFormatter.php index f00a5af..b89f94a 100644 --- a/src/Formatter/CurlCommandFormatter.php +++ b/src/Formatter/CurlCommandFormatter.php @@ -47,7 +47,7 @@ public function formatRequest(RequestInterface $request) } $escapedData = @escapeshellarg($data) or - die ("We couldn't not escape the data properly: error was '$php_errormsg'"); + die("We couldn't not escape the data properly: error was '$php_errormsg'"); $command .= sprintf(' --data %s', $escapedData); } From 0fe86eec4c4f8dabf595444f35ce78d682ef1199 Mon Sep 17 00:00:00 2001 From: llaakkkk Date: Wed, 7 Mar 2018 16:31:51 +0100 Subject: [PATCH 09/12] Fixed silently suppress error --- src/Formatter/CurlCommandFormatter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Formatter/CurlCommandFormatter.php b/src/Formatter/CurlCommandFormatter.php index b89f94a..e86c3fe 100644 --- a/src/Formatter/CurlCommandFormatter.php +++ b/src/Formatter/CurlCommandFormatter.php @@ -47,7 +47,7 @@ public function formatRequest(RequestInterface $request) } $escapedData = @escapeshellarg($data) or - die("We couldn't not escape the data properly: error was '$php_errormsg'"); + $escapedData = "We couldn't not escape the data properly"; $command .= sprintf(' --data %s', $escapedData); } From ac5ed4214cbd465d3422e346301e99c1e9691745 Mon Sep 17 00:00:00 2001 From: lakie Date: Wed, 6 Jun 2018 16:06:33 +0200 Subject: [PATCH 10/12] Fixed silently suppress error code readable --- src/Formatter/CurlCommandFormatter.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Formatter/CurlCommandFormatter.php b/src/Formatter/CurlCommandFormatter.php index e86c3fe..98bce0a 100644 --- a/src/Formatter/CurlCommandFormatter.php +++ b/src/Formatter/CurlCommandFormatter.php @@ -45,9 +45,11 @@ public function formatRequest(RequestInterface $request) } else { $data = '[non-seekable stream omitted]'; } - - $escapedData = @escapeshellarg($data) or - $escapedData = "We couldn't not escape the data properly"; + + $escapedData = @escapeshellarg($data); + if (empty($escapedData)) { + $escapedData = 'We couldn\'t not escape the data properly'; + } $command .= sprintf(' --data %s', $escapedData); } From 157d67d04026a3b8fec698c44e24b75e45f7f091 Mon Sep 17 00:00:00 2001 From: lakie Date: Wed, 6 Jun 2018 16:08:30 +0200 Subject: [PATCH 11/12] Fixed formatting --- src/Formatter/CurlCommandFormatter.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Formatter/CurlCommandFormatter.php b/src/Formatter/CurlCommandFormatter.php index 98bce0a..c46f94a 100644 --- a/src/Formatter/CurlCommandFormatter.php +++ b/src/Formatter/CurlCommandFormatter.php @@ -44,8 +44,7 @@ public function formatRequest(RequestInterface $request) } } else { $data = '[non-seekable stream omitted]'; - } - + } $escapedData = @escapeshellarg($data); if (empty($escapedData)) { $escapedData = 'We couldn\'t not escape the data properly'; From fd0c797c138cbad1c0526f00b1a120605f607375 Mon Sep 17 00:00:00 2001 From: llaakkkk Date: Wed, 6 Jun 2018 16:19:09 +0200 Subject: [PATCH 12/12] Fixed foramting --- src/Formatter/CurlCommandFormatter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Formatter/CurlCommandFormatter.php b/src/Formatter/CurlCommandFormatter.php index c46f94a..8060250 100644 --- a/src/Formatter/CurlCommandFormatter.php +++ b/src/Formatter/CurlCommandFormatter.php @@ -44,7 +44,7 @@ public function formatRequest(RequestInterface $request) } } else { $data = '[non-seekable stream omitted]'; - } + } $escapedData = @escapeshellarg($data); if (empty($escapedData)) { $escapedData = 'We couldn\'t not escape the data properly';