Skip to content

ext/dom: resolve in-scope prefixed QName values during document valid…#22224

Closed
devnexen wants to merge 3 commits into
php:PHP-8.4from
devnexen:gh22219-84
Closed

ext/dom: resolve in-scope prefixed QName values during document valid…#22224
devnexen wants to merge 3 commits into
php:PHP-8.4from
devnexen:gh22219-84

Conversation

@devnexen

@devnexen devnexen commented Jun 4, 2026

Copy link
Copy Markdown
Member

…ation.

Fix #22219

Modern DOM keeps namespace declarations off the tree (node->nsDef is NULL), so libxml's native validators cannot resolve a prefixed QName appearing in element or attribute content. Temporarily materialize them as nsDef entries around schema, RelaxNG and DTD validation, reusing the C14N relink machinery, then restore the tree.

…ation.

Fix php#22219

Modern DOM keeps namespace declarations off the tree (node->nsDef is NULL),
so libxml's native validators cannot resolve a prefixed QName appearing in
element or attribute content. Temporarily materialize them as nsDef entries
around schema, RelaxNG and DTD validation, reusing the C14N relink
machinery, then restore the tree.
@devnexen devnexen marked this pull request as ready for review June 4, 2026 05:28
Comment thread ext/dom/namespace_compat.h Outdated
* that libxml's native validators/canonicalizers can resolve prefixed QNames that
* appear in element/attribute *content*. Modern DOM keeps declarations off the
* tree (node->nsDef == NULL), which xmlSearchNs() cannot follow. */
PHP_DOM_EXPORT void dom_relink_ns_decls(HashTable *links, xmlNodePtr root);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These shouldn't become public APIs imo. It would also not be acceptable in a stable release.
The idea of this PR itself is fine.

Comment thread ext/dom/node.c Outdated
}

static void dom_relink_ns_decls(HashTable *links, xmlNodePtr root)
void dom_relink_ns_decls(HashTable *links, xmlNodePtr root)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the namespace relinking may be moved to namespace_compat.c

@ndossche ndossche left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, pls see my nit.

Comment thread ext/dom/namespace_compat.h Outdated
PHP_DOM_EXPORT php_dom_in_scope_ns php_dom_get_in_scope_ns_legacy(const xmlNode *node);
PHP_DOM_EXPORT void php_dom_in_scope_ns_destroy(php_dom_in_scope_ns *in_scope_ns);

/* Temporarily materialize namespace declarations as nsDef entries on the tree so

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Since this is an installed header file, perhaps this should be moved to the (massive) php_dom.h header instead.

@devnexen devnexen closed this in 3b5eeb9 Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants