From 05aea156caad2356bbd97231caaabc1531f35936 Mon Sep 17 00:00:00 2001 From: adev Date: Wed, 28 Jun 2017 22:58:24 +0200 Subject: [PATCH] Fix curl command of CurlFormatter when there is an user-agent header --- CHANGELOG.md | 4 ++++ spec/Formatter/CurlCommandFormatterSpec.php | 14 ++++++++++++++ src/Formatter/CurlCommandFormatter.php | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7511b80..65b054b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ - CookieUtil::parseDate to create a date from cookie date string +### Fixed + +- Fix curl command of CurlFormatter when there is an user-agent header + ## 1.5.0 - 2017-02-14 ### Added diff --git a/spec/Formatter/CurlCommandFormatterSpec.php b/spec/Formatter/CurlCommandFormatterSpec.php index 50fd374..4352827 100644 --- a/spec/Formatter/CurlCommandFormatterSpec.php +++ b/spec/Formatter/CurlCommandFormatterSpec.php @@ -58,4 +58,18 @@ function it_does_nothing_for_response(ResponseInterface $response) { $this->formatResponse($response)->shouldReturn(''); } + + function it_formats_the_request_with_user_agent(RequestInterface $request, UriInterface $uri, StreamInterface $body) + { + $request->getUri()->willReturn($uri); + $request->getBody()->willReturn($body); + + $uri->withFragment('')->shouldBeCalled()->willReturn('http://foo.com/bar'); + $request->getMethod()->willReturn('GET'); + $request->getProtocolVersion()->willReturn('1.1'); + $uri->withFragment('')->shouldBeCalled()->willReturn('http://foo.com/bar'); + $request->getHeaders()->willReturn(['user-agent'=>['foobar-browser']]); + + $this->formatRequest($request)->shouldReturn("curl 'http://foo.com/bar' -A 'foobar-browser'"); + } } diff --git a/src/Formatter/CurlCommandFormatter.php b/src/Formatter/CurlCommandFormatter.php index 5364ccc..a0fe7e5 100644 --- a/src/Formatter/CurlCommandFormatter.php +++ b/src/Formatter/CurlCommandFormatter.php @@ -68,7 +68,7 @@ private function getHeadersAsCommandOptions(RequestInterface $request) } if ('user-agent' === strtolower($name)) { - $command .= sprintf('-A %s', escapeshellarg($values[0])); + $command .= sprintf(' -A %s', escapeshellarg($values[0])); continue; }