-
Notifications
You must be signed in to change notification settings - Fork 7.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix bug #75779: DOMElement#setAttribute() does not process prefixed namespace declarations #3012
Conversation
…amespace declarations
Looks like what you're trying to fix is already done by Thanks. |
@weltling it can indeed be done that way, but the current behaviour of Moreover, currently what happens is that it creates a standard attribute named If the consensus is that a better approach would be to fail when this is attempted, then I guess that's OK too, but the current behaviour is definitely not correct and the most internally consistent to deal with it is with the approach taken by this patch, IMHO. |
@DaveRandom the specification about
The namespaces RFC
The PHP implementation seems to match both things. A qualified name needs to be declared and then can be used by default. Until i misread it. Regarding xmlSetProp - do you refer to some upstream issue? Thanks. |
@weltling PHP does deal with those things correctly, but it does extra things as well. See this demonstration, What this patch does is make the behaviour of The inconsistency exists because of the behaviour of |
Based on the previous conversation and further digging
Confirmed, maybe that has to raise an error if the namespace is not declared. Likely only should be done in master.
I'm not sure that's an issue. Talking about
and also
From that point, a code looks legit and should continue to function
which should be equivalent to
From that point, the usage of About the attribute counting - from that point it also seems logic. As in the first snippet, two attributes are added, so Thanks. |
The key point here (I think) is that libxml does not maintain namespace declarations as attributes, but PHP has added a layer to allow them to be inspected via $xml = <<<XML
<?xml version="1.0" ?>
<root xmlns:foo="uri:foo" />
XML;
$doc = new DOMDocument();
// This is a proxy for libxml's xmlParseDocument(), so does not rely on PHP having
// done "the correct thing"
$doc->loadXML($xml);
// These have special-case handling at the PHP level to redirect the lookup to the libxml
// namespace store
// https://lxr.room11.org/xref/php-src%407.2/ext/dom/element.c#285
var_dump($doc->documentElement->hasAttribute('xmlns:foo')); // bool(true)
var_dump($doc->documentElement->getAttribute('xmlns:foo')); // string(7) "uri:foo"
// This directly retrieves the libxml attribute store, which does not include the
// namespace declarations
// https://lxr.room11.org/xref/php-src%407.2/ext/dom/node.c#569
var_dump(count($doc->documentElement->attributes)); // int(0)
Because of the above, creating a libxml attribute node with the name
I also considered this, but I feel like this is going to break a lot of code which is using DOM to build XML documents, unless |
When I ran the code in the above comment I have also notices that the behaviour of |
Yeah, I'm checking the creation part with Java now, to get some comparison point. If that plays with The discrepancy between 7.1 and 7.2 as illustrated is a BC breach obviously, so were worth to investigate. This might be related to another change in the core, though. Given the libxml2 version used is same. Thanks. |
I've created a gist with the current experiments in Java here https://gist.github.com/weltling/da3f15d6acd23b2376097cf6c472e912 . Please note, that the DOM specification uses Java as a reference implementation. So far, i don't see the difference in the behavior, also in regard to Thanks. |
OK, I'm going to close this PR while I re-read the spec (again) and make sure I fully understand it. I think you are probably right, in that what I am trying to do is not allowed, and the reason I thought it should be allowed is because PHP is not throwing an error when it should be. If I have any further changes I will open them as PRs here so they can be reviewed. Thanks very much for your input and the work you have put in to reviewing this :-) |
Thanks for the discussion! Perhaps, the behavior change between 7.1 and 7.2 could be investigated, if one has time. Wondering, why it didn't popup till today :/ Thanks. |
The test suite for ext/dom is quite lacking at present, and I have never had cause to actually use I'm also reasonably certain that the fact that namespace declarations don't appear in I'm going to look at porting the DOM compliance test suite to phpt, but that is a huge job. I will see if I can come up with any tooling to automate it. |
This is because |
No description provided.