Fix GH-22825: DOM attribute methods on a DTD default attribute#22830
Closed
iliaal wants to merge 1 commit into
Closed
Fix GH-22825: DOM attribute methods on a DTD default attribute#22830iliaal wants to merge 1 commit into
iliaal wants to merge 1 commit into
Conversation
xmlHasNsProp() falls back to the internal subset, so the legacy ext/dom attribute methods can receive a DTD attribute declaration instead of an attribute node. setAttribute() and dom_remove_attribute() enumerated only XML_ATTRIBUTE_NODE and XML_NAMESPACE_DECL, so a defaulted attribute asserted on debug builds and ran into __builtin_unreachable() on release builds, and setAttributeNode() skipped the declaration when unlinking the old attribute but still returned it, throwing after the tree was already modified. setAttribute() now creates the attribute as it did before 8.4, matching setAttributeNS(); removeAttribute() reports that nothing was removed, since the declaration lives in the DTD and not on the element; setAttributeNode() returns null; and toggleAttribute() derives its result from the removal instead of assuming it succeeded, so the returned value keeps agreeing with hasAttribute(). getAttribute() and hasAttribute() already handled the declaration, and the Dom\Element methods are unaffected because the spec-compliant lookup never consults the DTD. Fixes phpGH-22825
devnexen
approved these changes
Jul 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
xmlHasNsProp()falls back to the internal subset, so on the legacy DOM an attribute lookup can return a DTD attribute declaration, and the switches over it never enumerated XML_ATTRIBUTE_DECL. EMPTY_SWITCH_DEFAULT_CASE compiles to__builtin_unreachable(), so instead of asserting, a release build silently returns false from setAttribute() and creates nothing. Any declaration carrying a default value hits this, not only #FIXED.setAttribute() now creates the attribute as it did before 8.4. removeAttribute() returns false for a declaration, which is an observable change. The read-only callers are left for a separate report.
Fixes #22825