summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXinchen Hui <laruence@gmail.com>2018-08-17 14:56:24 +0800
committerXinchen Hui <laruence@gmail.com>2018-08-17 14:56:24 +0800
commit751bbaa41fd64cf39554d75b8b8f02629f90de78 (patch)
tree5148b989531a23fa9a61297df74fb9088e8e2f7b
parentd61ff37f45de803ec45dd7f722bf4b51c3b0be02 (diff)
downloadphp-git-751bbaa41fd64cf39554d75b8b8f02629f90de78.tar.gz
Micro optimization & fixed invalid key handling
-rw-r--r--ext/session/tests/session_set_cookie_params_variation7.phpt4
-rw-r--r--ext/standard/head.c21
2 files changed, 11 insertions, 14 deletions
diff --git a/ext/session/tests/session_set_cookie_params_variation7.phpt b/ext/session/tests/session_set_cookie_params_variation7.phpt
index 9d1f8709be..1ab248908a 100644
--- a/ext/session/tests/session_set_cookie_params_variation7.phpt
+++ b/ext/session/tests/session_set_cookie_params_variation7.phpt
@@ -24,7 +24,7 @@ echo "*** Testing session_set_cookie_params() : array parameter variation ***\n"
// Invalid cases
var_dump(session_set_cookie_params([]));
-var_dump(session_set_cookie_params(["unknown_key" => true]));
+var_dump(session_set_cookie_params(["unknown_key" => true, "secure_invalid" => true]));
var_dump(ini_get("session.cookie_secure"));
var_dump(ini_get("session.cookie_samesite"));
@@ -51,6 +51,8 @@ bool(false)
Warning: session_set_cookie_params(): Unrecognized key 'unknown_key' found in the options array in %s
+Warning: session_set_cookie_params(): Unrecognized key 'secure_invalid' found in the options array in %s
+
Warning: session_set_cookie_params(): No valid keys were found in the options array in %s
bool(false)
string(1) "0"
diff --git a/ext/standard/head.c b/ext/standard/head.c
index 2ba68aabcf..c202e8f952 100644
--- a/ext/standard/head.c
+++ b/ext/standard/head.c
@@ -213,32 +213,28 @@ static int php_head_parse_cookie_options_array(zval *options, zend_long *expires
if (*path) {
*path = NULL;
- *domain = NULL;
- *secure = 0;
- *httponly = 0;
php_error_docref(NULL, E_WARNING, "Cannot pass arguments after the options array");
return 0;
}
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(options), key, value) {
if (key) {
- ZVAL_DEREF(value);
- if(!strcasecmp("expires", ZSTR_VAL(key))) {
+ if (zend_string_equals_literal_ci(key, "expires")) {
*expires = zval_get_long(value);
found++;
- } else if(!strcasecmp("path", ZSTR_VAL(key))) {
+ } else if (zend_string_equals_literal_ci(key, "path")) {
*path = zval_get_string(value);
found++;
- } else if(!strcasecmp("domain", ZSTR_VAL(key))) {
+ } else if (zend_string_equals_literal_ci(key, "domain")) {
*domain = zval_get_string(value);
found++;
- } else if(!strcasecmp("secure", ZSTR_VAL(key))) {
+ } else if (zend_string_equals_literal_ci(key, "secure")) {
*secure = zval_is_true(value);
found++;
- } else if(!strcasecmp("httponly", ZSTR_VAL(key))) {
+ } else if (zend_string_equals_literal_ci(key, "httponly")) {
*httponly = zval_is_true(value);
found++;
- } else if(!strcasecmp("samesite", ZSTR_VAL(key))) {
+ } else if (zend_string_equals_literal_ci(key, "samesite")) {
*samesite = zval_get_string(value);
found++;
} else {
@@ -265,7 +261,7 @@ PHP_FUNCTION(setcookie)
zval *expires_or_options = NULL;
zend_string *name, *value = NULL, *path = NULL, *domain = NULL, *samesite = NULL;
zend_long expires = 0;
- zend_bool secure = 0, httponly = 0, options_array = 0;
+ zend_bool secure = 0, httponly = 0;
ZEND_PARSE_PARAMETERS_START(1, 7)
Z_PARAM_STR(name)
@@ -280,7 +276,6 @@ PHP_FUNCTION(setcookie)
if (expires_or_options) {
if (Z_TYPE_P(expires_or_options) == IS_ARRAY) {
- options_array = 1;
if (!php_head_parse_cookie_options_array(expires_or_options, &expires, &path, &domain, &secure, &httponly, &samesite)) {
RETVAL_FALSE;
goto cleanup;
@@ -297,7 +292,7 @@ PHP_FUNCTION(setcookie)
}
cleanup:
- if (options_array) {
+ if (expires_or_options && Z_TYPE_P(expires_or_options) == IS_ARRAY) {
if (path) {
zend_string_release(path);
}