Bug #79344 [Opn]: XmlWriter::writeAttributeNS produces bad XML with null prefix

From: Date: Thu, 05 Mar 2020 08:05:48 +0000
Subject: Bug #79344 [Opn]: XmlWriter::writeAttributeNS produces bad XML with null prefix
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-225896@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79344&edit=1 ID: 79344 Updated by: cmb@php.net Reported by: jtojnar at gmail dot com Summary: XmlWriter::writeAttributeNS produces bad XML with null prefix Status: Open Type: Bug Package: XML Writer Operating System: NixOS PHP Version: 7.4.3 Block user comment: N Private report: N New Comment: The difference between passing NULL and an empty string to XMLWriter::writeAttributeNS() is that either NULL or an empty string is passed to xmlTextWriterWriteAttributeNS() (which does the actual work). The documentation of that function[1] is unfortunately not clear about whether there is a difference or not. So we can only observe the current libxml2 behavior, and it seems there is no difference. So I don't think there is anything we could do (except for calling xmlTextWriterWriteAttribute() if both prefix and uri are NULL, but that would constitute a BC break), besides documenting the behavior. http://xmlsoft.org/html/libxml-xmlwriter.html#xmlTextWriterWriteAttributeNS Previous Comments: ------------------------------------------------------------------------ [2020-03-04 16:38:53] jtojnar at gmail dot com Description: ------------ When passing a $prefix = null to XMLWriter::writeAttributeNs, it behaves as if empty string was passed, producing a non-well-formed XML document. Same issue happens with startAttributeNS method but it works fine for methods for creating elements. Test script: --------------- <?php $writer = new XMLWriter; $writer->openMemory(); $writer->setIndent(true); $writer->startElement('foo'); $writer->writeAttributeNS(null, 'test', null, 'test'); // $writer->startAttributeNS(null, 'test', null); // $writer->text('test'); // $writer->endAttribute(); $writer->endElement(); echo $writer->outputMemory(); Expected result: ---------------- <foo test="test"/> Actual result: -------------- <foo :test="test"/> ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=79344&edit=1

« previous php.bugs (#225896) next »