Skip to content

Commit 58a0bbc

Browse files
authored
Merge pull request #370 from aaronjorbin/fix/null-cookie-value
handle no domain in a PHP7.4 compatable way
2 parents 56286a0 + 355e379 commit 58a0bbc

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

library/Requests/Cookie.php

+5
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,11 @@ protected function normalize_attribute($name, $value) {
288288
return $expiry_time;
289289

290290
case 'domain':
291+
// Domains are not required as per RFC 6265 section 5.2.3
292+
if (empty($value)) {
293+
return null;
294+
}
295+
291296
// Domain normalization, as per RFC 6265 section 5.2.3
292297
if ($value[0] === '.') {
293298
$value = substr($value, 1);

tests/Cookies.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,13 @@ public function parseFromHeadersProvider() {
600600
array( 'invalid' => false ),
601601
),
602602

603+
# Empty Domain
604+
array(
605+
'name=value; domain=',
606+
'http://example.com/test/',
607+
array(),
608+
),
609+
603610
# Subdomain cookies
604611
array(
605612
'name=value; domain=test.example.com',
@@ -639,4 +646,4 @@ public function testParsingHeaderWithOrigin($header, $origin, $expected, $expect
639646
$cookie = reset($parsed);
640647
$this->check_parsed_cookie($cookie, $expected, $expected_attributes, $expected_flags);
641648
}
642-
}
649+
}

0 commit comments

Comments
 (0)