Skip to content

Commit

Permalink
Merge pull request #193 from Xerkus/fix/cookie-parsing
Browse files Browse the repository at this point in the history
Fix cookie parsing from headers in server request factory using globals.
  • Loading branch information
Xerkus authored Sep 10, 2024
2 parents 1f86ae1 + 949570d commit 6f63606
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
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

0 comments on commit 6f63606

Please sign in to comment.