Bug #75624 [Ver->Csd]: DOMNode::$prefix not NULL when unspecified

From: Date: Sat, 09 Mar 2024 16:09:06 +0000
Subject: Bug #75624 [Ver->Csd]: DOMNode::$prefix not NULL when unspecified
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-246549@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75624&edit=1 ID: 75624 Updated by: nielsdos@php.net Reported by: bit2shift at gmail dot com Summary: DOMNode::$prefix not NULL when unspecified -Status: Verified +Status: Closed Type: Bug Package: DOM XML related Operating System: Win7 Pro x64 PHP Version: 7.0.26 -Assigned To: +Assigned To: nielsdos Block user comment: N Private report: N New Comment: The fix for this bug has been committed. If you are still experiencing this bug, try to check out latest source from https://github.com/php/php-src and re-test. Thank you for the report, and for helping us make PHP better. This is fixed in the new opt-in spec-compliance mode, which was merged in https://github.com/php/php-src/pull/13031. For more information about the opt-in mode, please see https://wiki.php.net/rfc/opt_in_dom_spec_compliance. In short: the behaviour of the old DOM classes are unaffected for backwards-compatibility reasons. There are new DOM classes where your code is correctly handled. This feature will be available in PHP 8.4. Previous Comments: ------------------------------------------------------------------------ [2017-12-04 22:15:19] bit2shift at gmail dot com For what it's worth, this bug goes all the way to the bleeding-edge 7.2 https://github.com/php/php-src/blob/master/ext/dom/node.c#L693 ------------------------------------------------------------------------ [2017-12-04 17:18:47] requinix@php.net Note that 5.6 is only receiving security fixes. DOM 3 does indeed say it should be null if unspecified. Same bug for textContent: should be null for DOCUMENT_NODE, DOCUMENT_TYPE_NODE, and NOTATION_NODE where currently PHP will force an empty string. ------------------------------------------------------------------------ [2017-12-04 17:11:00] bit2shift at gmail dot com https://github.com/php/php-src/blob/PHP-5.6.32/ext/dom/node.c#L757 This seems to be the origin, it should be ZVAL_NULL(*retval). ------------------------------------------------------------------------ [2017-12-04 16:52:58] bit2shift at gmail dot com Description: ------------ --- From manual page: http://www.php.net/class.domnode --- The documentation states that $prefix is NULL if it is unspecified, but instead I'm getting an empty string. This causes an annoyance when passing it through to XMLWriter::startElementNs(), as it'll output (an example) <:derp> instead of <derp>. Test script: --------------- <?php $doc = new DOMDocument(); $doc->loadXML('<derp></derp>'); $root = $doc->documentElement; echo "prefix: [$root->prefix]<br>"; echo "name: [$root->localName]<br>"; echo 'is the prefix NULL? ' . (is_null($root->prefix) ? 'yep' : 'nope'); var_dump($root); Expected result: ---------------- prefix: [] name: [derp] is the prefix NULL? yep --omitted--\test.php:9: object(DOMElement)[2] public 'tagName' => string 'derp' (length=4) public 'schemaTypeInfo' => null public 'nodeName' => string 'derp' (length=4) public 'nodeValue' => string '' (length=0) public 'nodeType' => int 1 public 'parentNode' => string '(object value omitted)' (length=22) public 'childNodes' => string '(object value omitted)' (length=22) public 'firstChild' => null public 'lastChild' => null public 'previousSibling' => null public 'attributes' => string '(object value omitted)' (length=22) public 'ownerDocument' => string '(object value omitted)' (length=22) public 'namespaceURI' => null public 'prefix' => null public 'localName' => string 'derp' (length=4) public 'baseURI' => string 'file:/--omitted--/' (length=46) public 'textContent' => string '' (length=0) Actual result: -------------- prefix: [] name: [derp] is the prefix NULL? nope --omitted--\test.php:9: object(DOMElement)[2] public 'tagName' => string 'derp' (length=4) public 'schemaTypeInfo' => null public 'nodeName' => string 'derp' (length=4) public 'nodeValue' => string '' (length=0) public 'nodeType' => int 1 public 'parentNode' => string '(object value omitted)' (length=22) public 'childNodes' => string '(object value omitted)' (length=22) public 'firstChild' => null public 'lastChild' => null public 'previousSibling' => null public 'attributes' => string '(object value omitted)' (length=22) public 'ownerDocument' => string '(object value omitted)' (length=22) public 'namespaceURI' => null public 'prefix' => string '' (length=0) public 'localName' => string 'derp' (length=4) public 'baseURI' => string 'file:/--omitted--/' (length=46) public 'textContent' => string '' (length=0) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75624&edit=1

« previous php.bugs (#246549) next »