diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f29d07..fde1022 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## Unreleased +### Fixed + +- Fixed Fatal error on `CurlCommandFormatter` when body is larger than `escapeshellarg` allowed length. + ## [1.7.2] - 2018-10-30 ### Fixed diff --git a/spec/Formatter/CurlCommandFormatterSpec.php b/spec/Formatter/CurlCommandFormatterSpec.php index 5340b62..f68d7e2 100644 --- a/spec/Formatter/CurlCommandFormatterSpec.php +++ b/spec/Formatter/CurlCommandFormatterSpec.php @@ -108,4 +108,22 @@ function it_formats_requests_with_nonseekable_body(RequestInterface $request, Ur $this->formatRequest($request)->shouldReturn("curl 'http://foo.com/bar' --request POST --data '[non-seekable stream omitted]'"); } + + function it_formats_requests_with_long_body(RequestInterface $request, UriInterface $uri, StreamInterface $body) + { + $request->getUri()->willReturn($uri); + $request->getBody()->willReturn($body); + + $body->__toString()->willReturn('a very long body'); + $body->getSize()->willReturn(2097153); + $body->isSeekable()->willReturn(true); + $body->rewind()->willReturn(true); + + $uri->withFragment('')->willReturn('http://foo.com/bar'); + $request->getMethod()->willReturn('POST'); + $request->getProtocolVersion()->willReturn('1.1'); + $request->getHeaders()->willReturn([]); + + $this->formatRequest($request)->shouldReturn("curl 'http://foo.com/bar' --request POST --data '[too long stream omitted]'"); + } } diff --git a/src/Formatter/CurlCommandFormatter.php b/src/Formatter/CurlCommandFormatter.php index 8060250..2ddb149 100644 --- a/src/Formatter/CurlCommandFormatter.php +++ b/src/Formatter/CurlCommandFormatter.php @@ -36,7 +36,10 @@ public function formatRequest(RequestInterface $request) $body = $request->getBody(); if ($body->getSize() > 0) { - if ($body->isSeekable()) { + // escapeshellarg argument max length on Windows, but longer body in curl command would be impractical anyways + if ($body->getSize() > 8192) { + $data = '[too long stream omitted]'; + } elseif ($body->isSeekable()) { $data = $body->__toString(); $body->rewind(); if (preg_match('/[\x00-\x1F\x7F]/', $data)) {