com php-src: Fix #67131: setcookie() conditional for empty values not met: ext/standard/head.c ext/standard/tests/network/setcookie.phpt
| From: | Christoph Michael Becker | Date: | Mon, 24 Aug 2015 21:03:50 +0000 |
| Subject: | com php-src: Fix #67131: setcookie() conditional for empty values not met: ext/standard/head.c ext/standard/tests/network/setcookie.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-88746@lists.php.net to get a copy of this message | ||
Commit: fc203fa37eb0454c94e7e30f3b4e5fc81b699699
Author: Christoph M. Becker <cmb@php.net> Mon, 24 Aug 2015 23:03:50 +0200
Parents: 78b2b1d6f74705d7835bf34297c2c6c78b2d0601
Branches: PHP-5.6 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=fc203fa37eb0454c94e7e30f3b4e5fc81b699699
Log:
Fix #67131: setcookie() conditional for empty values not met
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.
Bugs:
https://bugs.php.net/67131
Changed paths:
M ext/standard/head.c
M ext/standard/tests/network/setcookie.phpt
Diff:
diff --git a/ext/standard/head.c b/ext/standard/head.c
index f66c604..56a48a0 100644
--- a/ext/standard/head.c
+++ b/ext/standard/head.c
@@ -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
diff --git a/ext/standard/tests/network/setcookie.phpt b/ext/standard/tests/network/setcookie.phpt
index bf04ec7..f63c6ec 100644
--- a/ext/standard/tests/network/setcookie.phpt
+++ b/ext/standard/tests/network/setcookie.phpt
@@ -6,6 +6,7 @@ date.timezone=UTC
--FILE--
<?php
setcookie('name');
+setcookie('name', '');
setcookie('name', 'value');
setcookie('name', 'space value');
setcookie('name', 'value', 0);
@@ -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',
@@ -64,6 +66,7 @@ while (next($headers) !== FALSE);
echo ($i === 0)
? 'OK'
: 'A total of '.$i.' errors found.';
+?>
--EXPECTHEADERS--
--EXPECT--