Skip to content

Try to use an interned local name in createElementNS #14127

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
May 4, 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
12 changes: 11 additions & 1 deletion ext/dom/document.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down