Bug #75779 [NEW]: DOMElement#setAttribute() does not process prefixed namespace declarations

From: Date: Mon, 08 Jan 2018 16:33:03 +0000
Subject: Bug #75779 [NEW]: DOMElement#setAttribute() does not process prefixed namespace declarations
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-213427@lists.php.net to get a copy of this message
From:             daverandom
Operating system: Any
PHP version:      7.1.13
Package:          DOM XML related
Bug Type:         Bug
Bug description:DOMElement#setAttribute() does not process prefixed namespace declarations

Description:
------------
DOMElement#setAttribute() correctly handles setting the default
(unprefixed) namespace, but does not handle prefixed namespaces, and
simply creates a DOMAttr and appends it to the node.

Test script:
---------------
$xml = '<?xml version="1.0" ?><test />';
$doc = new DOMDocument();
$doc->loadXML($xml);

$element = $doc->documentElement;

// Unprefixed works fine

echo "\nElement should not have namespace:\n";
var_dump($element->lookupPrefix('test:unprefixed'),
$element->lookupNamespaceURI(null));

echo "\nsetAttribute() call should succeed:\n";
var_dump($element->setAttribute('xmlns', 'test:unprefixed'));

echo "\nElement should have xmlns attribute:\n";
var_dump($element->hasAttribute('xmlns'));

echo "\nElement should have namespace:\n";
var_dump($element->lookupPrefix('test:unprefixed'),
$element->lookupNamespaceURI(null));

// Prefixed does not work

echo "\nElement should not have namespace:\n";
var_dump($element->lookupPrefix('test:prefixed'),
$element->lookupNamespaceURI('test'));

echo "\nsetAttribute() call should succeed:\n";
var_dump($element->setAttribute('xmlns:test', 'test:prefixed'));

echo "\nElement should have xmlns attribute:\n";
var_dump($element->hasAttribute('xmlns:test'));

echo "\nElement should have namespace:\n";
var_dump($element->lookupPrefix('test:prefixed'),
$element->lookupNamespaceURI('test'));


Expected result:
----------------
Namespace is registered with prefix

Actual result:
--------------
DOMAttr is added to node but namespace is not registered

-- 
Edit bug report at https://bugs.php.net/bug.php?id=75779&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=75779&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=75779&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=75779&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=75779&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=75779&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=75779&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=75779&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=75779&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=75779&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=75779&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=75779&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=75779&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=75779&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75779&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=75779&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=75779&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=75779&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=75779&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=75779&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=75779&r=mysqlcfg



Thread (3 messages)

« previous php.bugs (#213427) next »