From: Michael Wallner Date: Wed, 29 Aug 2007 16:21:57 +0000 (+0000) Subject: - fix bug #11929 http_negotiate_* does not return default value on non-match X-Git-Tag: RELEASE_1_6_0b1~5 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=f3fefe49c3c19564bddacaebd5fecb6de231b988;p=m6w6%2Fext-http - fix bug #11929 http_negotiate_* does not return default value on non-match --- diff --git a/http_functions.c b/http_functions.c index 2c849c1..d915b3f 100644 --- a/http_functions.c +++ b/http_functions.c @@ -148,6 +148,17 @@ PHP_FUNCTION(http_build_str) } /* }}} */ +#define HTTP_DO_NEGOTIATE_DEFAULT(supported) \ + { \ + zval **value; \ + \ + zend_hash_internal_pointer_reset(Z_ARRVAL_P(supported)); \ + if (SUCCESS == zend_hash_get_current_data(Z_ARRVAL_P(supported), (void *) &value)) { \ + RETVAL_ZVAL(*value, 1, 0); \ + } else { \ + RETVAL_NULL(); \ + } \ + } #define HTTP_DO_NEGOTIATE(type, supported, rs_array) \ { \ HashTable *result; \ @@ -156,10 +167,10 @@ PHP_FUNCTION(http_build_str) uint key_len; \ ulong idx; \ \ - if (HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(result, &key, &key_len, &idx, 1, NULL)) { \ + if (zend_hash_num_elements(result) && HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(result, &key, &key_len, &idx, 1, NULL)) { \ RETVAL_STRINGL(key, key_len-1, 0); \ } else { \ - RETVAL_NULL(); \ + HTTP_DO_NEGOTIATE_DEFAULT(supported); \ } \ \ if (rs_array) { \ @@ -170,14 +181,7 @@ PHP_FUNCTION(http_build_str) FREE_HASHTABLE(result); \ \ } else { \ - zval **value; \ - \ - zend_hash_internal_pointer_reset(Z_ARRVAL_P(supported)); \ - if (SUCCESS == zend_hash_get_current_data(Z_ARRVAL_P(supported), (void *) &value)) { \ - RETVAL_ZVAL(*value, 1, 0); \ - } else { \ - RETVAL_NULL(); \ - } \ + HTTP_DO_NEGOTIATE_DEFAULT(supported); \ \ if (rs_array) { \ HashPosition pos; \ diff --git a/tests/negotiation_001.phpt b/tests/negotiation_001.phpt index d4b13ac..3641455 100644 --- a/tests/negotiation_001.phpt +++ b/tests/negotiation_001.phpt @@ -26,10 +26,14 @@ var_dump(http_negotiate_charset($csets[0])); var_dump(http_negotiate_charset($csets[0], $cresult)); var_dump(http_negotiate_content_type($ctype[0])); var_dump(http_negotiate_content_type($ctype[0], $tresult)); +var_dump(http_negotiate_language(array("unknown"))); +var_dump(http_negotiate_charset(array("unknown"))); +var_dump(http_negotiate_content_type(array("unknown"))); print_r($lresult); print_r($cresult); print_r($tresult); echo "Done\n"; +?> --EXPECTF-- %sTEST string(2) "de" @@ -38,6 +42,9 @@ string(10) "iso-8859-1" string(10) "iso-8859-1" string(21) "application/xhtml+xml" string(21) "application/xhtml+xml" +string(7) "unknown" +string(7) "unknown" +string(7) "unknown" Array ( [de] => 900