php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #79344 xmlwriter_write_attribute_ns: $prefix should be nullable
Submitted: 2020-03-04 16:38 UTC Modified: 2020-06-16 13:52 UTC
From: jtojnar at gmail dot com Assigned: cmb (profile)
Status: Closed Package: XML Writer
PHP Version: 7.4.3 OS: NixOS
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jtojnar at gmail dot com
New email:
PHP Version: OS:

 

 [2020-03-04 16:38 UTC] 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"/>


Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-03-05 08:05 UTC] cmb@php.net
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
 [2020-03-05 08:30 UTC] nikic@php.net
@cmb: Are you sure that's the reason? Looking at the implementation, $prefix is accepted as s, not s!, so we will cast NULL to "".
 [2020-06-16 12:16 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2020-06-16 12:16 UTC] cmb@php.net
Indeed, @nikic, my analysis was nonsense.  The point is that the
$prefix parameter is not nullable.
 [2020-06-16 12:17 UTC] cmb@php.net
The following pull request has been associated:

Patch Name: FR #79344: xmlwriter_write_attribute_ns: $prefix should be nullable
On GitHub:  https://github.com/php/php-src/pull/5724
Patch:      https://github.com/php/php-src/pull/5724.patch
 [2020-06-16 13:49 UTC] cmb@php.net
-Summary: XmlWriter::writeAttributeNS produces bad XML with null prefix +Summary: xmlwriter_write_attribute_ns: $prefix should be nullable -Type: Bug +Type: Feature/Change Request
 [2020-06-16 13:49 UTC] cmb@php.net
Not strictly a bug; changing to feature request.
 [2020-06-16 13:52 UTC] cmb@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 14 14:01:26 2024 UTC