Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cookie parsing from headers in server request factory using globals. #193

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.25.0@01a8eb06b9e9cc6cfb6a320bf9fb14331919d505">
<files psalm-version="5.26.0@4787eaf414e16c661902b94dfe5d882223e5b513">
<file src="src/AbstractSerializer.php">
<RedundantCondition>
<code><![CDATA[! $crFound]]></code>
Expand Down Expand Up @@ -190,9 +190,6 @@
<code><![CDATA[$headers]]></code>
<code><![CDATA[$server]]></code>
</MixedArgumentTypeCoercion>
<RedundantConditionGivenDocblockType>
<code><![CDATA[is_callable(self::$apacheRequestHeaders)]]></code>
</RedundantConditionGivenDocblockType>
</file>
<file src="src/ServerRequestFilter/FilterUsingXForwardedHeaders.php">
<ImpureMethodCall>
Expand Down
12 changes: 6 additions & 6 deletions src/ServerRequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ServerRequestFactory implements ServerRequestFactoryInterface
/**
* Function to use to get apache request headers; present only to simplify mocking.
*
* @var callable
* @var callable|string
*/
private static $apacheRequestHeaders = 'apache_request_headers';

Expand All @@ -35,11 +35,11 @@ class ServerRequestFactory implements ServerRequestFactoryInterface
*
* @see fromServer()
*
* @param array $server $_SERVER superglobal
* @param array $query $_GET superglobal
* @param array $body $_POST superglobal
* @param array $cookies $_COOKIE superglobal
* @param array $files $_FILES superglobal
* @param null|array $server $_SERVER superglobal
* @param null|array $query $_GET superglobal
* @param null|array $body $_POST superglobal
* @param null|array $cookies $_COOKIE superglobal
* @param null|array $files $_FILES superglobal
* @param null|FilterServerRequestInterface $requestFilter If present, the
* generated request will be passed to this instance and the result
* returned by this method. When not present, a default instance of
Expand Down
4 changes: 2 additions & 2 deletions src/functions/parse_cookie_header.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Laminas\Diactoros;

use function preg_match_all;
use function urldecode;
use function rawurldecode;

use const PREG_SET_ORDER;

Expand Down Expand Up @@ -33,7 +33,7 @@ function parseCookieHeader($cookieHeader): array
$cookies = [];

foreach ($matches as $match) {
$cookies[$match['name']] = urldecode($match['value']);
$cookies[$match['name']] = rawurldecode($match['value']);
}

return $cookies;
Expand Down
2 changes: 1 addition & 1 deletion test/ServerRequestFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public static function cookieHeaderValues(): array
],
'url-encoded-value' => [
'foo=bar%3B+',
['foo' => 'bar; '],
['foo' => 'bar;+'],
],
'double-quoted-value' => [
'foo="bar"',
Expand Down