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

From: Date: Sat, 09 Mar 2024 16:09:15 +0000
Subject: Bug #75779 [Opn]: DOMElement#setAttribute() does not process prefixed namespace declarations
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-246550@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75779&edit=1 ID: 75779 Updated by: nielsdos@php.net Reported by: daverandom@php.net Summary: DOMElement#setAttribute() does not process prefixed namespace declarations Status: Open Type: Bug Package: DOM XML related Operating System: Any PHP Version: 7.1.13 Block user comment: N Private report: N New Comment: 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: ------------------------------------------------------------------------ [2018-01-08 16:33:01] 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 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75779&edit=1

« previous php.bugs (#246550) next »