Try to use an interned local name in createElementNS (#14127)

This commit is contained in:
Niels Dossche 2024-05-04 13:59:43 +02:00 committed by GitHub
parent 234b3cb241
commit 22a113b99c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -912,7 +912,17 @@ PHP_METHOD(DOM_Document, createElementNS)
if (errorcode == 0) {
php_dom_libxml_ns_mapper *ns_mapper = php_dom_get_ns_mapper(intern);
xmlNsPtr ns = php_dom_libxml_ns_mapper_get_ns_raw_prefix_string(ns_mapper, prefix, xmlStrlen(prefix), uri);
xmlNodePtr nodep = xmlNewDocNodeEatName(docp, ns, localname, NULL);
/* Try to create the node with the local name interned. */
const xmlChar *interned_localname = xmlDictLookup(docp->dict, localname, -1);
xmlNodePtr nodep;
if (interned_localname == NULL) {
nodep = xmlNewDocNodeEatName(docp, ns, localname, NULL);
} else {
xmlFree(localname);
nodep = xmlNewDocNodeEatName(docp, ns, BAD_CAST interned_localname, NULL);
}
if (UNEXPECTED(nodep == NULL)) {
php_dom_throw_error(INVALID_STATE_ERR, /* strict */ true);
} else {