Skip to content

Commit 17ed3b0

Browse files
committed
feedback
1 parent 6ef3863 commit 17ed3b0

1 file changed

Lines changed: 16 additions & 15 deletions

File tree

ext/dom/node.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2128,22 +2128,10 @@ static xmlNsPtr dom_alloc_ns_decl(HashTable *links, xmlNodePtr node)
21282128
return ns;
21292129
}
21302130

2131-
/* For DOM-built documents (e.g. createElementNS), namespaces live on node->ns
2132-
* without corresponding xmlns attributes. C14N expects nsDef entries, so create
2133-
* temporary ones. The _private field stays NULL to distinguish from attr-based
2134-
* entries during cleanup. */
2131+
/* Mint a temporary nsDef entry so C14N finds namespaces that live on node->ns
2132+
* but have no matching xmlns attribute (typical for createElementNS). */
21352133
static void dom_add_synthetic_ns_decl(HashTable *links, xmlNodePtr node, xmlNsPtr src_ns)
21362134
{
2137-
/* Pre-existing nsDef entries are never filled in for Dom\XMLDocument.
2138-
* This loop guards against duplicates from our own synthetic additions
2139-
* within the same C14N pass (e.g. when an element and its attributes
2140-
* share the same namespace prefix). */
2141-
for (xmlNsPtr existing = node->nsDef; existing; existing = existing->next) {
2142-
if (xmlStrEqual(existing->prefix, src_ns->prefix)) {
2143-
return;
2144-
}
2145-
}
2146-
21472135
xmlNsPtr ns = dom_alloc_ns_decl(links, node);
21482136
if (!ns) {
21492137
return;
@@ -2153,6 +2141,19 @@ static void dom_add_synthetic_ns_decl(HashTable *links, xmlNodePtr node, xmlNsPt
21532141
ns->prefix = src_ns->prefix ? xmlStrdup(src_ns->prefix) : NULL;
21542142
}
21552143

2144+
/* Same, but for attribute namespaces, which may collide by prefix with the
2145+
* element's own ns or with a sibling attribute's ns. */
2146+
static void dom_add_synthetic_ns_decl_for_attr(HashTable *links, xmlNodePtr node, xmlNsPtr src_ns)
2147+
{
2148+
for (xmlNsPtr existing = node->nsDef; existing; existing = existing->next) {
2149+
if (xmlStrEqual(existing->prefix, src_ns->prefix)) {
2150+
return;
2151+
}
2152+
}
2153+
2154+
dom_add_synthetic_ns_decl(links, node, src_ns);
2155+
}
2156+
21562157
static void dom_relink_ns_decls_element(HashTable *links, xmlNodePtr node)
21572158
{
21582159
if (node->type == XML_ELEMENT_NODE) {
@@ -2185,7 +2186,7 @@ static void dom_relink_ns_decls_element(HashTable *links, xmlNodePtr node)
21852186
}
21862187
for (xmlAttrPtr attr = node->properties; attr; attr = attr->next) {
21872188
if (attr->ns && !php_dom_ns_is_fast((const xmlNode *) attr, php_dom_ns_is_xmlns_magic_token)) {
2188-
dom_add_synthetic_ns_decl(links, node, attr->ns);
2189+
dom_add_synthetic_ns_decl_for_attr(links, node, attr->ns);
21892190
}
21902191
}
21912192

0 commit comments

Comments
 (0)