Skip to content

Commit 22a113b

Browse files
authored
Try to use an interned local name in createElementNS (#14127)
1 parent 234b3cb commit 22a113b

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

ext/dom/document.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,17 @@ PHP_METHOD(DOM_Document, createElementNS)
912912
if (errorcode == 0) {
913913
php_dom_libxml_ns_mapper *ns_mapper = php_dom_get_ns_mapper(intern);
914914
xmlNsPtr ns = php_dom_libxml_ns_mapper_get_ns_raw_prefix_string(ns_mapper, prefix, xmlStrlen(prefix), uri);
915-
xmlNodePtr nodep = xmlNewDocNodeEatName(docp, ns, localname, NULL);
915+
916+
/* Try to create the node with the local name interned. */
917+
const xmlChar *interned_localname = xmlDictLookup(docp->dict, localname, -1);
918+
xmlNodePtr nodep;
919+
if (interned_localname == NULL) {
920+
nodep = xmlNewDocNodeEatName(docp, ns, localname, NULL);
921+
} else {
922+
xmlFree(localname);
923+
nodep = xmlNewDocNodeEatName(docp, ns, BAD_CAST interned_localname, NULL);
924+
}
925+
916926
if (UNEXPECTED(nodep == NULL)) {
917927
php_dom_throw_error(INVALID_STATE_ERR, /* strict */ true);
918928
} else {

0 commit comments

Comments
 (0)