Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions php_json_post.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ PHP_MINFO_FUNCTION(json_post)
static SAPI_POST_HANDLER_FUNC(php_json_post_handler)
{
int module_number = 0;
int error_code;

#if PHP_VERSION_ID >= 70000
zend_string *json = NULL;
Expand Down Expand Up @@ -95,7 +96,7 @@ static SAPI_POST_HANDLER_FUNC(php_json_post_handler)
case IS_OBJECT:
case IS_ARRAY:
if (zend_hash_num_elements(HASH_OF(&tmp))) {
zval_dtor(arg);
zval_ptr_dtor_nogc(arg);
ZVAL_COPY_VALUE(&PG(http_globals)[TRACK_VARS_POST], &tmp);
} else {
/* PHP-7.4 optimizes empty array */
Expand Down Expand Up @@ -136,7 +137,7 @@ static SAPI_POST_HANDLER_FUNC(php_json_post_handler)
# if PHP_VERSION_ID >= 50400
php_json_decode_ex(&zjson, json_str, json_len, JSON_POST_G(flags), PG(max_input_nesting_level) TSRMLS_CC);
if (Z_TYPE(zjson) != IS_NULL) {
zval_dtor(zarg);
zval_ptr_dtor_nogc(zarg);
ZVAL_COPY_VALUE(zarg, (&zjson));
# else
php_json_decode(&zjson, json_str, json_len, (zend_bool)(JSON_POST_G(flags)&1), PG(max_input_nesting_level) TSRMLS_CC);
Expand All @@ -154,14 +155,19 @@ static SAPI_POST_HANDLER_FUNC(php_json_post_handler)
# endif
#endif

REGISTER_LONG_CONSTANT("JSON_POST_ERROR", JSON_G(error_code), CONST_CS);
#if PHP_VERSION_ID < 80600
error_code = JSON_G(error_code);
#else
error_code = JSON_G(error_details.code);
#endif
REGISTER_LONG_CONSTANT("JSON_POST_ERROR", error_code, CONST_CS);

if (JSON_G(error_code)) {
if (error_code) {
if (JSON_POST_G(onerror.response)) {
sapi_header_op(SAPI_HEADER_SET_STATUS, (void *) (zend_long) JSON_POST_G(onerror.response) TSRMLS_CC);
}
if (JSON_POST_G(onerror.warning)) {
zend_error(E_WARNING, "json_post: json_decode failed with error code: %d", JSON_G(error_code));
zend_error(E_WARNING, "json_post: json_decode failed with error code: %d", error_code);
}
if (JSON_POST_G(onerror.exit)) {
sapi_send_headers(TSRMLS_C);
Expand Down
2 changes: 1 addition & 1 deletion tests/error.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ if ($_POST)
var_dump(compact("_POST"));
if (PHP_VERSION_ID >= 70000 && ($json_last_error = json_last_error()))
var_dump(compact("json_last_error"));
if (($JSON_POST_ERROR = JSON_POST_ERROR) !== (PHP_VERSION_ID < 70000 ? 4 : 3))
if (($JSON_POST_ERROR = JSON_POST_ERROR) !== (PHP_VERSION_ID < 70000 || PHP_VERSION_ID >= 80600 ? 4 : 3))
var_dump(compact("JSON_POST_ERROR"));
if (($http_response_code = http_response_code()) != ini_get("json_post.onerror.response") && ini_get("json_post.onerror.response"))
var_dump(compact("http_response_code"));
Expand Down
Loading