From 663c9a3b77b71463fa7fcb76a6676ffd16979dd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Tue, 16 Aug 2022 18:30:57 +0200 Subject: [PATCH] Do not decode cookie names anymore --- README.md | 4 ++-- examples/55-server-cookie-handling.php | 4 ++-- src/Message/ServerRequest.php | 2 +- tests/Message/ServerRequestTest.php | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ba8d8330..1070349c 100644 --- a/README.md +++ b/README.md @@ -1304,7 +1304,7 @@ get all cookies sent with the current request. ```php $http = new React\Http\HttpServer(function (Psr\Http\Message\ServerRequestInterface $request) { - $key = 'react\php'; + $key = 'greeting'; if (isset($request->getCookieParams()[$key])) { $body = "Your cookie value is: " . $request->getCookieParams()[$key] . "\n"; @@ -1316,7 +1316,7 @@ $http = new React\Http\HttpServer(function (Psr\Http\Message\ServerRequestInterf return React\Http\Message\Response::plaintext( "Your cookie has been set.\n" - )->withHeader('Set-Cookie', urlencode($key) . '=' . urlencode('test;more')); + )->withHeader('Set-Cookie', $key . '=' . urlencode('Hello world!')); }); ``` diff --git a/examples/55-server-cookie-handling.php b/examples/55-server-cookie-handling.php index 796da24d..b5e68862 100644 --- a/examples/55-server-cookie-handling.php +++ b/examples/55-server-cookie-handling.php @@ -3,7 +3,7 @@ require __DIR__ . '/../vendor/autoload.php'; $http = new React\Http\HttpServer(function (Psr\Http\Message\ServerRequestInterface $request) { - $key = 'react\php'; + $key = 'greeting'; if (isset($request->getCookieParams()[$key])) { $body = "Your cookie value is: " . $request->getCookieParams()[$key] . "\n"; @@ -15,7 +15,7 @@ return React\Http\Message\Response::plaintext( "Your cookie has been set.\n" - )->withHeader('Set-Cookie', urlencode($key) . '=' . urlencode('test;more')); + )->withHeader('Set-Cookie', $key . '=' . urlencode('Hello world!')); }); $socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '0.0.0.0:0'); diff --git a/src/Message/ServerRequest.php b/src/Message/ServerRequest.php index f446f24e..fdb3ec5e 100644 --- a/src/Message/ServerRequest.php +++ b/src/Message/ServerRequest.php @@ -186,7 +186,7 @@ private function parseCookie($cookie) $nameValuePair = \explode('=', $pair, 2); if (\count($nameValuePair) === 2) { - $key = \urldecode($nameValuePair[0]); + $key = $nameValuePair[0]; $value = \urldecode($nameValuePair[1]); $result[$key] = $value; } diff --git a/tests/Message/ServerRequestTest.php b/tests/Message/ServerRequestTest.php index 37cc1879..a5919f64 100644 --- a/tests/Message/ServerRequestTest.php +++ b/tests/Message/ServerRequestTest.php @@ -251,7 +251,7 @@ public function testUrlEncodingForKeyWillReturnValidArray() ); $cookies = $this->request->getCookieParams(); - $this->assertEquals(array('react;php' => 'is great'), $cookies); + $this->assertEquals(array('react%3Bphp' => 'is great'), $cookies); } public function testCookieWithoutSpaceAfterSeparatorWillBeAccepted()