Skip to content

Cleanup dom_html_document_encoding_write() #13788

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 23, 2024
Merged
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
15 changes: 4 additions & 11 deletions ext/dom/html_document.c
Original file line number Diff line number Diff line change
Expand Up @@ -1342,12 +1342,8 @@ zend_result dom_html_document_encoding_write(dom_object *obj, zval *newval)
{
DOM_PROP_NODE(xmlDocPtr, docp, obj);

/* Typed property, can only be IS_STRING or IS_NULL. */
ZEND_ASSERT(Z_TYPE_P(newval) == IS_STRING || Z_TYPE_P(newval) == IS_NULL);

if (Z_TYPE_P(newval) == IS_NULL) {
goto invalid_encoding;
}
/* Typed property, can only be IS_STRING. */
ZEND_ASSERT(Z_TYPE_P(newval) == IS_STRING);

zend_string *str = Z_STR_P(newval);
const lxb_encoding_data_t *encoding_data = lxb_encoding_data_by_name((const lxb_char_t *) ZSTR_VAL(str), ZSTR_LEN(str));
Expand All @@ -1356,14 +1352,11 @@ zend_result dom_html_document_encoding_write(dom_object *obj, zval *newval)
xmlFree(BAD_CAST docp->encoding);
docp->encoding = xmlStrdup((const xmlChar *) encoding_data->name);
} else {
goto invalid_encoding;
zend_value_error("Invalid document encoding");
return FAILURE;
}

return SUCCESS;

invalid_encoding:
zend_value_error("Invalid document encoding");
return FAILURE;
}

#endif /* HAVE_LIBXML && HAVE_DOM */