Skip to content

Commit

Permalink
Define namespaces as close to the element as possible
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsdos committed Dec 17, 2023
1 parent 40d14f7 commit 4295e2a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
8 changes: 5 additions & 3 deletions ext/dom/document.c
Original file line number Diff line number Diff line change
Expand Up @@ -872,8 +872,10 @@ PHP_METHOD(DOM_Document, createElementNS)
errorcode = dom_validate_and_extract(uri, name, &localname, &prefix);

if (errorcode == 0) {
xmlNsPtr ns = dom_ns_create_local_as_is(docp, xmlDocGetRootElement(docp), uri, prefix);
nodep = xmlNewDocRawNode(docp, ns, localname, BAD_CAST value);
nodep = xmlNewDocRawNode(docp, NULL, localname, BAD_CAST value);
if (EXPECTED(nodep != NULL)) {
nodep->ns = dom_ns_create_local_as_is(docp, nodep, xmlDocGetRootElement(docp), uri, prefix);
}
}

xmlFree(localname);
Expand Down Expand Up @@ -957,7 +959,7 @@ PHP_METHOD(DOM_Document, createAttributeNS)

if (uri != NULL && ZSTR_LEN(uri) > 0) {
if (php_dom_follow_spec_intern(intern)) {
nsptr = dom_ns_create_local_as_is(docp, root, uri, prefix);
nsptr = dom_ns_create_local_as_is(docp, root, root, uri, prefix);
} else {
nsptr = xmlSearchNsByHref(docp, root, BAD_CAST ZSTR_VAL(uri));

Expand Down
4 changes: 2 additions & 2 deletions ext/dom/namespace_compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ static xmlNsPtr dom_ns_create_local_as_is_unchecked(xmlDocPtr doc, xmlNodePtr pa
return ns;
}

xmlNsPtr dom_ns_create_local_as_is(xmlDocPtr doc, xmlNodePtr parent, zend_string *uri, xmlChar *prefix)
xmlNsPtr dom_ns_create_local_as_is(xmlDocPtr doc, xmlNodePtr ns_holder, xmlNodePtr parent, zend_string *uri, xmlChar *prefix)
{
ZEND_ASSERT(doc != NULL);

Expand All @@ -141,7 +141,7 @@ xmlNsPtr dom_ns_create_local_as_is(xmlDocPtr doc, xmlNodePtr parent, zend_string
}
}

return dom_ns_create_local_as_is_unchecked(doc, parent, href, prefix);
return dom_ns_create_local_as_is_unchecked(doc, ns_holder, href, prefix);
}

xmlNsPtr dom_ns_fast_get_html_ns(xmlDocPtr docp)
Expand Down
2 changes: 1 addition & 1 deletion ext/dom/namespace_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ extern const dom_ns_magic_token *dom_ns_is_xmlns_magic_token;
void dom_ns_compat_mark_attribute_list(xmlNodePtr node);
bool dom_ns_is_fast(const xmlNode *nodep, const dom_ns_magic_token *magic_token);
bool dom_ns_is_html_and_document_is_html(const xmlNode *nodep);
xmlNsPtr dom_ns_create_local_as_is(xmlDocPtr doc, xmlNodePtr parent, zend_string *uri, xmlChar *prefix);
xmlNsPtr dom_ns_create_local_as_is(xmlDocPtr doc, xmlNodePtr ns_holder, xmlNodePtr parent, zend_string *uri, xmlChar *prefix);
xmlNsPtr dom_ns_fast_get_html_ns(xmlDocPtr docp);

#endif

0 comments on commit 4295e2a

Please sign in to comment.