PHP :: Bug #75779 :: DOMElement#setAttribute() does not process prefixed namespace declarations
php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75779 DOMElement#setAttribute() does not process prefixed namespace declarations
Submitted: 2018-01-08 16:33 UTC Modified: -
From: daverandom@php.net Assigned:
Status: Open Package: DOM XML related
PHP Version: 7.1.13 OS: Any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: daverandom@php.net
New email:
PHP Version: OS:

 

 [2018-01-08 16:33 UTC] daverandom@php.net
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

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Fri Aug 17 18:01:26 2018 UTC