Skip to content

Commit

Permalink
Fix #67131: setcookie() conditional for empty values not met
Browse files Browse the repository at this point in the history
PHP applies a workaround for old MSIE where setting an empty cookie value would
not delete the cookie. This workaround is only triggered if an empty string (or
a value that converts to an empty string) is actually given as $value parameter
of setcookie. If the $value parameter is omitted, an empty cookie value is
sent. This commit fixes the inconsistent behavior.
  • Loading branch information
cmb69 committed Aug 24, 2015
1 parent 78b2b1d commit fc203fa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ext/standard/head.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ PHPAPI int php_setcookie(char *name, int name_len, char *value, int value_len, t

cookie = emalloc(len + 100);

if (value && value_len == 0) {
if (value == NULL || value_len == 0) {
/*
* MSIE doesn't delete a cookie when you set it to a null value
* so in order to force cookies to be deleted, even on MSIE, we
Expand Down
5 changes: 4 additions & 1 deletion ext/standard/tests/network/setcookie.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ date.timezone=UTC
--FILE--
<?php
setcookie('name');
setcookie('name', '');
setcookie('name', 'value');
setcookie('name', 'space value');
setcookie('name', 'value', 0);
Expand All @@ -19,7 +20,8 @@ setcookie('name', 'value', 0, '', '', FALSE, TRUE);


$expected = array(
'Set-Cookie: name=',
'Set-Cookie: name=deleted; expires='.date('D, d-M-Y H:i:s', 1).' GMT; Max-Age=0',
'Set-Cookie: name=deleted; expires='.date('D, d-M-Y H:i:s', 1).' GMT; Max-Age=0',
'Set-Cookie: name=value',
'Set-Cookie: name=space+value',
'Set-Cookie: name=value',
Expand Down Expand Up @@ -64,6 +66,7 @@ while (next($headers) !== FALSE);
echo ($i === 0)
? 'OK'
: 'A total of '.$i.' errors found.';
?>
--EXPECTHEADERS--

--EXPECT--
Expand Down

0 comments on commit fc203fa

Please sign in to comment.