Bug #75624 [Opn->Ver]: DOMNode::$prefix not NULL when unspecified
| From: | requinix@php.net | Date: | Mon, 04 Dec 2017 17:18:49 +0000 |
| Subject: | Bug #75624 [Opn->Ver]: DOMNode::$prefix not NULL when unspecified | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-212914@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: requinix@php.net
Reported by: bit2shift at gmail dot com
Summary: DOMNode::$prefix not NULL when unspecified
-Status: Open
+Status: Verified
Type: Bug
Package: DOM XML related
Operating System: Win7 Pro x64
-PHP Version: 5.6.32
+PHP Version: 7.0.26
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[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