Skip to content

Commit 8002fae

Browse files
GaryPEGEOTdbu
authored andcommitted
Fix fatal error for long bodies (#116)
* Fix fatal error for long bodies * Set body size limit to 8192 * Phrasing
1 parent 8991386 commit 8002fae

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
99

1010
## Unreleased
1111

12+
### Fixed
13+
14+
- Fixed Fatal error on `CurlCommandFormatter` when body is larger than `escapeshellarg` allowed length.
15+
1216
## [1.7.2] - 2018-10-30
1317

1418
### Fixed

spec/Formatter/CurlCommandFormatterSpec.php

+18
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,22 @@ function it_formats_requests_with_nonseekable_body(RequestInterface $request, Ur
108108

109109
$this->formatRequest($request)->shouldReturn("curl 'http://foo.com/bar' --request POST --data '[non-seekable stream omitted]'");
110110
}
111+
112+
function it_formats_requests_with_long_body(RequestInterface $request, UriInterface $uri, StreamInterface $body)
113+
{
114+
$request->getUri()->willReturn($uri);
115+
$request->getBody()->willReturn($body);
116+
117+
$body->__toString()->willReturn('a very long body');
118+
$body->getSize()->willReturn(2097153);
119+
$body->isSeekable()->willReturn(true);
120+
$body->rewind()->willReturn(true);
121+
122+
$uri->withFragment('')->willReturn('http://foo.com/bar');
123+
$request->getMethod()->willReturn('POST');
124+
$request->getProtocolVersion()->willReturn('1.1');
125+
$request->getHeaders()->willReturn([]);
126+
127+
$this->formatRequest($request)->shouldReturn("curl 'http://foo.com/bar' --request POST --data '[too long stream omitted]'");
128+
}
111129
}

src/Formatter/CurlCommandFormatter.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ public function formatRequest(RequestInterface $request)
3636

3737
$body = $request->getBody();
3838
if ($body->getSize() > 0) {
39-
if ($body->isSeekable()) {
39+
// escapeshellarg argument max length on Windows, but longer body in curl command would be impractical anyways
40+
if ($body->getSize() > 8192) {
41+
$data = '[too long stream omitted]';
42+
} elseif ($body->isSeekable()) {
4043
$data = $body->__toString();
4144
$body->rewind();
4245
if (preg_match('/[\x00-\x1F\x7F]/', $data)) {

0 commit comments

Comments
 (0)