GNOME Bugzilla – Bug 520674
xmlNewTextWriterFilename incorrectly rejects some uris
Last modified: 2021-07-05 13:22:44 UTC
Please describe the problem: The xmlNewTextWriterFilename function rejects some uris that have a scheme but no authority, such as file:/home/sthomas/file.xml. If you insert an empty authority component, as in file:///home/sthomas/file.xml, it works. The xmlReaderForFile function has no problem with authority-less uris. Steps to reproduce: // Here's a program that demonstrates the problem #include <string> #include <iostream> #include <libxml/xmlreader.h> #include <libxml/xmlwriter.h> using namespace std; void attemptReadFile(string uri) { xmlTextReaderPtr reader = xmlReaderForFile(uri.c_str(), NULL, 0); cout << "read " << uri << " " << (reader ? "succeeded" : "failed") << endl; xmlFreeTextReader(reader); } void attemptWriteFile(string uri) { xmlTextWriterPtr writer = xmlNewTextWriterFilename(uri.c_str(), 0); cout << "write " << uri << " " << (writer ? "succeeded" : "failed") << endl; xmlFreeTextWriter(writer); } int main() { // Creating an xmlTextWriter without an authority component in the uri // fails. It works for xmlTextReaders... attemptReadFile("/home/sthomas/file.xml"); // Works attemptReadFile("file:/home/sthomas/file.xml"); // Works attemptReadFile("file:///home/sthomas/file.xml"); // Works // ... but not xmlTextWriters attemptWriteFile("/home/sthomas/file2.xml"); // Works attemptWriteFile("file:/home/sthomas/file2.xml"); // Fails! attemptWriteFile("file:///home/sthomas/file2.xml"); // Works return 0; } Actual results: Writing to the uri "file:/home/sthomas/file2.xml" fails. Expected results: Writing to that uri should work fine. Does this happen every time? Yes Other information:
GNOME is going to shut down bugzilla.gnome.org in favor of gitlab.gnome.org. As part of that, we are mass-closing older open tickets in bugzilla.gnome.org which have not seen updates for a longer time (resources are unfortunately quite limited so not every ticket can get handled). If you can still reproduce the situation described in this ticket in a recent and supported software version, then please follow https://wiki.gnome.org/GettingInTouch/BugReportingGuidelines and create a new ticket at https://gitlab.gnome.org/GNOME/libxml2/-/issues/ Thank you for your understanding and your help.