[SimpleXML] Fix creating new attributes via attributes() dimension write - #264
Open
iliaal wants to merge 1 commit into
Open
[SimpleXML] Fix creating new attributes via attributes() dimension write#264iliaal wants to merge 1 commit into
iliaal wants to merge 1 commit into
Conversation
sxe_prop_dim_write() overwrote the element node with the first attribute node when resolving an SXE_ITER_ATTRLIST iterator, so xmlNewProp() targeted a non-element node and was skipped entirely when no attribute existed yet. Keep the element node in place and resolve only the attribute list start, so $x->attributes()["new"] = "v" creates the attribute like the symmetric $x["new"] path; property writes on the attributes() object share the fixed path while read/exists/unset handlers are unaffected by this defect.
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.
Writing to a dimension of the object returned by SimpleXMLElement::attributes(), such as $x->attributes()["new"] = "v", silently did nothing when the attribute did not already exist, because sxe_prop_dim_write() replaced the element node with the first attribute node while resolving an SXE_ITER_ATTRLIST iterator, so xmlNewProp() was either called on a non-element node or never reached at all when the element had no attributes yet. The fix keeps the element node in place and only resolves the start of the attribute list, making dimension writes on attributes() behave like the equivalent $x["new"] = "v" path; property writes on the attributes() object share this code path and are fixed as well, while the read, exists, and unset handlers are unaffected since they have no creation semantics.