-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fixes setcookie to only send one Set-Cookie header per name #849
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--TEST-- | ||
setcookie() emits 2 cookies with same name with display_error off | ||
--DESCRIPTION-- | ||
--INI-- | ||
display_errors=0 | ||
--FILE-- | ||
<?php | ||
setcookie('name', 'value'); | ||
setcookie('name', 'value'); | ||
|
||
$expected = array( | ||
'Set-Cookie: name=value', | ||
'Set-Cookie: name=value', | ||
); | ||
|
||
$headers = headers_list(); | ||
|
||
// Filter to get only the Set-Cookie headers | ||
$cookie_headers = []; | ||
foreach ($headers as $header) { | ||
if (strpos($header, 'Set-Cookie:') === 0) $cookie_headers[] = $header; | ||
} | ||
|
||
if (count($cookie_headers) !== count($expected)) { | ||
echo "Less headers are being sent than expected - aborting"; | ||
return; | ||
} | ||
|
||
$bad = 0; | ||
|
||
foreach ($cookie_headers as $i => $header) { | ||
if ($header !== $expected[$i]) { | ||
$bad++; | ||
echo "Header mismatch:\n\tExpected: " | ||
. $expected[$i] | ||
. "\n\tReceived: " | ||
. $header | ||
. "\n"; | ||
} | ||
} | ||
|
||
echo ($bad === 0) | ||
? 'OK' | ||
: 'A total of ' . $bad . ' errors found.'; | ||
--EXPECTHEADERS-- | ||
|
||
--EXPECT-- | ||
OK |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--TEST-- | ||
setcookie() emits 1 cookie then adds a warning for 2nd with same name | ||
--DESCRIPTION-- | ||
--INI-- | ||
--FILE-- | ||
<?php | ||
|
||
setcookie('name', 'value'); | ||
setcookie('name', 'value'); | ||
|
||
$expected = array( | ||
'Set-Cookie: name=value', | ||
); | ||
|
||
$headers = headers_list(); | ||
|
||
// Filter to get only the Set-Cookie headers | ||
$cookie_headers = []; | ||
foreach ($headers as $header) { | ||
if (strpos($header, 'Set-Cookie:') === 0) $cookie_headers[] = $header; | ||
} | ||
|
||
if (count($cookie_headers) !== count($expected)) { | ||
echo "Less headers are being sent than expected - aborting"; | ||
return; | ||
} | ||
--EXPECTHEADERS-- | ||
|
||
--EXPECTF-- | ||
|
||
Warning: setcookie(): should not be used twice with the same name in %s | ||
|
||
Warning: Cannot modify header information - headers already sent by %s |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,6 +137,7 @@ typedef struct _sapi_globals_struct { | |
zval callback_func; | ||
zend_fcall_info_cache fci_cache; | ||
zend_bool callback_run; | ||
HashTable *cookies; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe a inline struct here is better , HashTable cookies.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's wrong with
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean you can use a inline Hashtable here instead of a Hashtable *, that will avoid Hashtable allocating/freeing. |
||
} sapi_globals_struct; | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's better also print the duplicated cookie name here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I'll see how I can phrase this.
Le 28 sept. 2014 07:38, "Xinchen Hui" notifications@github.com a écrit :