Replaced standard http_build_query by guzzle's build_query, which keeps params with no value

This commit is contained in:
Alejandro Celaya
2020-01-12 10:26:59 +01:00
parent 127f7e80f5
commit cc8474aefb
2 changed files with 3 additions and 11 deletions

View File

@@ -20,8 +20,8 @@ use Zend\Diactoros\Uri;
use function array_key_exists;
use function array_merge;
use function GuzzleHttp\Psr7\build_query;
use function GuzzleHttp\Psr7\parse_query;
use function http_build_query;
abstract class AbstractTrackingAction implements MiddlewareInterface
{
@@ -46,15 +46,6 @@ abstract class AbstractTrackingAction implements MiddlewareInterface
$this->logger = $logger ?: new NullLogger();
}
/**
* Process an incoming server request and return a response, optionally delegating
* to the next middleware component to create the response.
*
* @param ServerRequestInterface $request
* @param RequestHandlerInterface $handler
*
* @return ResponseInterface
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$shortCode = $request->getAttribute('shortCode', '');
@@ -86,7 +77,7 @@ abstract class AbstractTrackingAction implements MiddlewareInterface
}
$mergedQuery = array_merge($hardcodedQuery, $currentQuery);
return (string) $uri->withQuery(http_build_query($mergedQuery));
return (string) $uri->withQuery(build_query($mergedQuery));
}
abstract protected function createSuccessResp(string $longUrl): ResponseInterface;

View File

@@ -67,6 +67,7 @@ class RedirectActionTest extends TestCase
{
yield ['http://domain.com/foo/bar?some=thing', []];
yield ['http://domain.com/foo/bar?some=thing', ['foobar' => 'notrack']];
yield ['http://domain.com/foo/bar?some=thing&else', ['else' => null]];
yield ['http://domain.com/foo/bar?some=thing&foo=bar', ['foo' => 'bar']];
yield ['http://domain.com/foo/bar?some=overwritten&foo=bar', ['foo' => 'bar', 'some' => 'overwritten']];
yield ['http://domain.com/foo/bar?some=overwritten', ['foobar' => 'notrack', 'some' => 'overwritten']];