ext/soap: Refactor to_zval_bool() (#18696)

- Early return style
- Improve logic to get rid of unnecessary comparisons
- Do not use convert_to_boolean API
This commit is contained in:
Gina Peter Banyard 2025-05-29 15:29:55 +01:00 committed by GitHub
parent 407c9781f9
commit c9e571560f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1118,29 +1118,27 @@ static xmlNodePtr to_xml_double(encodeTypePtr type, zval *data, int style, xmlNo
static zval *to_zval_bool(zval *ret, encodeTypePtr type, xmlNodePtr data)
{
ZVAL_NULL(ret);
FIND_XML_NULL(data, ret);
if (data && data->children) {
if (data->children->type == XML_TEXT_NODE && data->children->next == NULL) {
whiteSpace_collapse(data->children->content);
if (stricmp((char*)data->children->content, "true") == 0 ||
stricmp((char*)data->children->content, "t") == 0 ||
strcmp((char*)data->children->content, "1") == 0) {
ZVAL_TRUE(ret);
} else if (stricmp((char*)data->children->content, "false") == 0 ||
stricmp((char*)data->children->content, "f") == 0 ||
strcmp((char*)data->children->content, "0") == 0) {
ZVAL_FALSE(ret);
} else {
ZVAL_STRING(ret, (char*)data->children->content);
convert_to_boolean(ret);
}
} else {
soap_error0(E_ERROR, "Encoding: Violation of encoding rules");
}
} else {
if (!data->children) {
ZVAL_NULL(ret);
return ret;
}
if (data->children->type != XML_TEXT_NODE || data->children->next != NULL) {
// TODO Convert to exception?
soap_error0(E_ERROR, "Encoding: Violation of encoding rules");
}
whiteSpace_collapse(data->children->content);
if (
data->children->content[0] == '\0' /* Check for empty string */
|| strcmp((const char*)data->children->content, "0") == 0
|| stricmp((const char*)data->children->content, "f") == 0
|| stricmp((const char*)data->children->content, "false") == 0
) {
ZVAL_FALSE(ret);
} else {
ZVAL_TRUE(ret);
}
return ret;
}