Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 276d239

Browse files
committed
parse cookie values containing the equal sign
1 parent 426bf96 commit 276d239

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/Symfony/Component/HttpFoundation/HeaderUtils.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public static function makeDisposition(string $disposition, string $filename, st
193193
return $disposition.'; '.self::toString($params, ';');
194194
}
195195

196-
private static function groupParts(array $matches, string $separators): array
196+
private static function groupParts(array $matches, string $separators, bool $first = true): array
197197
{
198198
$separator = $separators[0];
199199
$partSeparators = substr($separators, 1);
@@ -211,12 +211,19 @@ private static function groupParts(array $matches, string $separators): array
211211
$parts = [];
212212
if ($partSeparators) {
213213
foreach ($partMatches as $matches) {
214-
$parts[] = self::groupParts($matches, $partSeparators);
214+
$parts[] = self::groupParts($matches, $partSeparators, false);
215215
}
216216
} else {
217217
foreach ($partMatches as $matches) {
218218
$parts[] = self::unquote($matches[0][0]);
219219
}
220+
221+
if (!$first && 2 < count($parts)) {
222+
$parts = [
223+
$parts[0],
224+
implode($separator, array_slice($parts, 1)),
225+
];
226+
}
220227
}
221228

222229
return $parts;

src/Symfony/Component/HttpFoundation/Tests/CookieTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,12 @@ public function testFromString()
227227

228228
$cookie = Cookie::fromString('foo', true);
229229
$this->assertEquals(Cookie::create('foo', null, 0, '/', null, false, false, false, null), $cookie);
230+
231+
$cookie = Cookie::fromString('foo_cookie=foo=1&bar=2&baz=3; expires=Tue, 22-Sep-2020 06:27:09 GMT; path=/');
232+
$this->assertEquals(Cookie::create('foo_cookie', 'foo=1&bar=2&baz=3', strtotime('Tue, 22-Sep-2020 06:27:09 GMT'), '/', null, false, false, true, null), $cookie);
233+
234+
$cookie = Cookie::fromString('foo_cookie=foo==; expires=Tue, 22-Sep-2020 06:27:09 GMT; path=/');
235+
$this->assertEquals(Cookie::create('foo_cookie', 'foo==', strtotime('Tue, 22-Sep-2020 06:27:09 GMT'), '/', null, false, false, true, null), $cookie);
230236
}
231237

232238
public function testFromStringWithHttpOnly()

src/Symfony/Component/HttpFoundation/Tests/HeaderUtilsTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public function testSplit()
3535
$this->assertSame(['foo bar'], HeaderUtils::split('"foo" bar', ','));
3636
$this->assertSame(['foo bar'], HeaderUtils::split('"foo" "bar"', ','));
3737

38+
$this->assertSame([['foo_cookie', 'foo=1&bar=2&baz=3'], ['expires', 'Tue, 22-Sep-2020 06:27:09 GMT'], ['path', '/']], HeaderUtils::split('foo_cookie=foo=1&bar=2&baz=3; expires=Tue, 22-Sep-2020 06:27:09 GMT; path=/', ';='));
39+
3840
// These are not a valid header values. We test that they parse anyway,
3941
// and that both the valid and invalid parts are returned.
4042
$this->assertSame([], HeaderUtils::split('', ','));

0 commit comments

Comments
 (0)