Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104692 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 16348 invoked from network); 13 Mar 2019 18:46:32 -0000 Received: from unknown (HELO a2i400.smtp2go.com) (103.47.205.144) by pb1.pair.com with SMTP; 13 Mar 2019 18:46:32 -0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=smtpcorp.com; s=a1-4; h=Feedback-ID:X-Smtpcorp-Track:Date:Message-ID:From: To:Subject:Reply-To:Sender:List-Unsubscribe; bh=ZDYKLLd0d2qKZaBt1k9LtzarNSywddD24RnIY2Doaus=; b=BqLV9cgHEunSNMkafvxQKvcvWJ PzJPlnia7wMQpAO6vjvHezAJNgVAsRmVMQgTxW7sR61VB2ki4atGiub2B6W2xfeSU5BPL9MNIC2AX GQd0iYieh9RUsVrLpRdwFbqDTnd+AxzWIU2nAhGEa6iY6lmRZ7scWEXfI9EGYmwgqry91KRDgtI2d AQt0b2Fck40dV3EI2oerCL0AB3nyfYe3pIhTk2kPiQ9FQGxI2atCDpGhUP5L3PkS/r0wJy3qYxsBo /CR/z9noF7rnaut/Zu+7DINQJ0DwGIjIMSPdR8aoKiUdlQ1rkU1O13oJZ2d5jXJvh2Q98dtwRg6xs 9iy8Gxeg==; Received: from [10.103.47.204] (helo=SmtpCorp) by smtpcorp.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.91) (envelope-from ) id 1h45vt-pH9Sfd-6N; Wed, 13 Mar 2019 15:36:41 +0000 Received: from [10.199.83.220] (helo=Robs-MacBook-Pro.local) by smtpcorp.com with esmtp (Exim 4.91) (envelope-from ) id 1h45vs-U24clG-Fz; Wed, 13 Mar 2019 15:36:40 +0000 To: Pierre Joye , Benjamin Eberlei Cc: PHP internals References: Openpgp: preference=signencrypt Autocrypt: addr=rrichards@ctindustries.net; prefer-encrypt=mutual; keydata= mQINBFo8IZ4BEADQXfpzxwmnlHpx333Clq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gwISetUaS8HhGWNS16uL+7rWd9Ntcj8Mb84/IegOYHIRHFts/zwiyuMmQki6W B12H0ITgkfCU/d4nxbLcZQARAQABiQI8BBgBCAAmFiEEwO1R4Lve98qHHkUlflDxS081CzcF Alo8IZ4CGwwFCQeGH4AACgkQflDxS081CzdwnA//cw/6jcrsk8bIr9R+QbBdlUXKwPQ/milj 7aoY8r5wG8oBlzJNPjChiaFPB878hsrPEMuwpARn0MLoxoEtA7cC6rXJq9Go71/xsTyikpSv nkZNljeWdC0av30eo7byE6kMPvCUiWq6MaY2GkV8vfvuYCEQLdIzqIv1P91R9qWGcV1vE4Gn JHdXYw6fvH7A8Hg5heq8EEhZSz4+mYuyygpCBhs9j/loERWULeCTI0E4PmjrcLFGxAD6ulte RUzZke+8/s4z6uPLyrX//On0G0ftwvZ6syU7xF7dARFgvTErZeiRoMle8D3EMMZsydSz7/v2 edhbGB1yZaIqV5012MZQFv8HoqideriJ7C/F+gsvPuyBb/7UNYSVO4qLH5n+x7QFXWaaCmYL 1AujbYbq7lz7avp2eL1QFRC6sTdouYlb9zMMF9ERCTW7G84xh2d6xHOD5SGFgGTDaeICKpr3 jmNVhifiZAXgAWfZjhS25rpalyPBPGBF5yJCGyuKZdpuz2ltt83HkHyby3xuzbnyjNHMwsrk 1i3jRmJQ9pa8S9F/+502pNXwFbWKUScOwrwpCsetnsfQyDsGS6DmWBM7Zt8hBW/ALas9a85T 4rKiYBlqnYbLVDgf8CeoXWA3cNjf5lstMfMWzCSzG16v5emcXGFsR1owvo16p5DlCl2eKpYL Cvk= Message-ID: <08e09ea4-20d0-277d-8919-4e3d4387699c@ctindustries.net> Date: Wed, 13 Mar 2019 08:36:37 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.5.3 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------CBE04BCA57C28820921D6A16" Content-Language: en-US X-Smtpcorp-Track: 1h45vsl24c_GFz.i-OJepyL0 Feedback-ID: 2192m:2192ahkZ5OI:2192sitGAit-g7 X-Report-Abuse: Please forward a copy of this message, including all headers, to Subject: Re: [PHP-DEV] On fixing DOMNameSpaceNode and DOM NS API Inconsistency Problems From: rrichards@ctindustries.net (Rob Richards) --------------CBE04BCA57C28820921D6A16 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit There were specific reasons for it tho I can't recall all the details off the top of my head. Part of it related to the underlying structures of attributes and namespace nodes not being the same and cannot be user interchangeable in the code, unless only inspected at the nodeptr level. Trying to manipulate namespace nodes as attributes will cause memory corruption so they need to be handled differently. I don't remember if this was the only reason or there was more for the special class but while I agree with basic DOM usage no one should ever need to be dealing directly with namespace declarations but once you get into more complex situation, especially that involve xpath, xslt, canonicalization and even interoperability this starts coming into play and is quite important to deal with namespace declarations directly. Also some of the examples in previous messages are way overly simplistic so the conclusions are not 100% accurate. i.e. removeAttributeNS. I am assuming that its just due to overly aggressive namespace reconciliation happening and removing the declaration since its no longer in use. With a nested document which uses the namespace in child nodes I would expect the namespace declaration to remain, tho possible it may be moved to the first child using it (been a while since I looked at that code). My recommendation would be to tread lightly here, look at every method any changes to namespace declaration nodes would touch and make sure they are all handle properly otherwise you run the risk of introducing memory corruption issues which is far worse than some inconsistency for supposedly unused and unneeded functionality ;) BTW I have recently started looking at the libxml code base again and considering getting more involved here again, assuming the toxicity level has gone done from the past. Not sure this is the first thing I would look at but feel free to shoot over any questions. Rob On 3/12/19 1:50 AM, Pierre Joye wrote: > Hi, > > Only adding Rob just in case :) > > best, > > On Wed, Mar 13, 2019, 5:54 AM Benjamin Eberlei > wrote: > > Hi everyone, > > While looking for things to work on in php-src my friend Thomas > pointed me > to a peculiar special case in ext/dom that leads to massive > inconsistency > problems in the API. > > There is an undocumented class DOMNameSpaceNode that gets returned > from > DOMElement::getAttributeNode(NS) if you select an attribute that > represents > a namespace (xmlns). This special case is intentionally handled in the > code, contrary to Pythons DOM Extension which doesn't do this and > contrary > to the DOM Specification, which does not have a special > DOMNameSpaceNode. > Its all DOMAttr. > > Problematically DOMNameSpaceNode doesn't extend from DOMAttr, you > cannot > pass this class to DOMElement::removeAttributeNode(DOMAttr $attr): > >     Fatal error: Uncaught TypeError: Argument 1 passed to > DOMElement::removeAttributeNode() must be an instance of DOMAttr, > instance > of DOMNameSpaceNode given > > Code example here: https://3v4l.org/jkC5s > > In addition the DOMNameSpaceNode renames all properties compared to > DOMAttr, clearly violating the interface documented here > http://php.net/manual/de/domelement.getattributenode.php > > Two potential fixes come to mind: > > 1. Have DOMNameSpaceNode extend DOMAttr - maybe this was the > originally > intended behavior, becuase the properties are all named differently? > 2. Have DOMElement::removeAttributeNode accept also a DOMNameSpaceNode > (3.) Remove the non standard DOMNameSpaceNode class and use a DOMAttr > instead > > I think approach #1 is the right one from a BC perspective and > also fixing > the DOM API to be more consistent with the standard. > > But I am also not opposed to #3 in the longer term, looking at Github > DOMNamespaceNode in the open source world is only used for one apc > test, in > PHP Compat and when dumping it in Symfony Var Dumper. I imagine > its more > deeply used in closed source code working deeply with XML. > > The second problem that this inconsistency creates is > DOMElement::removeAttributeNS($namespaceUri, $localName). When you > want to > use it to remove a namespace attribute (xmlns). By default the xmlns > namespace has the uri http://www.w3.org/2000/xmlns/. Hence removing > xmlns:$name namespace would expected to be: > > DOMElement::removeAttributeNS("http://www.w3.org/2000/xmlns/", > "foo") // > removes xmlns:foo > > But thats not how it works, there is special code implemented that > requires > you to pick the URI from xmlns:foo value: > > > > DOMElement::removeAttributeNS("urn:foo", "foo"); > > But if your node has an attribute in this namespace with the same > name, it > gets removed as well: > > > > Would incorrectly become this, removing 2 attributes: > > > > This is a bug that cannot be fixed in a BC way. I have no clue how > to fix > this completly broken behavior in a good way. I propose to break > BC here > and requiring "http://www.w3.org/2000/xmlns/" as namespaceURI from > PHP 8.0 > to delete a namespace (xmlns) attribute. > > Should I put both issues into an RFC or are these rather bugs that > can be > fixed without an RFC? > > greetings > Benjamin > --------------CBE04BCA57C28820921D6A16--