|  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 Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
46 - 18 = ?
Subscribe to this entry?

 [2020-03-04 16:38 UTC] jtojnar at gmail dot com
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:

$writer = new XMLWriter;

$writer->writeAttributeNS(null, 'test', null, 'test');
// $writer->startAttributeNS(null, 'test', null);
// $writer->text('test');
// $writer->endAttribute();

echo $writer->outputMemory();

Expected result:
<foo test="test"/>

Actual result:
<foo :test="test"/>


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-03-05 08:05 UTC]
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
 [2020-03-05 08:30 UTC]
@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]
-Assigned To: +Assigned To: cmb
 [2020-06-16 12:16 UTC]
Indeed, @nikic, my analysis was nonsense.  The point is that the
$prefix parameter is not nullable.
 [2020-06-16 12:17 UTC]
The following pull request has been associated:

Patch Name: FR #79344: xmlwriter_write_attribute_ns: $prefix should be nullable
On GitHub:
 [2020-06-16 13:49 UTC]
-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]
Not strictly a bug; changing to feature request.
 [2020-06-16 13:52 UTC]
-Status: Assigned +Status: Closed
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 26 15:01:29 2024 UTC