Skip to content

Commit 8eb9969

Browse files
authored
Add support for LIBXML_NOXMLDECL for modern documents (#14209)
This wasn't supported before, but should be.
1 parent e95b06c commit 8eb9969

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
Serialize modern document with LIBXML_NOXMLDECL
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
8+
$dom = Dom\XMLDocument::createFromString('<?xml version="1.0"?><root/>');
9+
echo $dom->saveXml(options: LIBXML_NOXMLDECL), "\n";
10+
11+
?>
12+
--EXPECT--
13+
<root/>

ext/dom/xml_document.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,12 @@ static int php_new_dom_write_smart_str(void *context, const char *buffer, int le
257257
return len;
258258
}
259259

260-
static zend_string *php_new_dom_dump_node_to_str(xmlDocPtr doc, xmlNodePtr node, bool format, const char *encoding)
260+
static zend_string *php_new_dom_dump_node_to_str_ex(xmlNodePtr node, int options, bool format, const char *encoding)
261261
{
262262
smart_str str = {0};
263263

264264
int status = -1;
265-
xmlSaveCtxtPtr ctxt = xmlSaveToIO(php_new_dom_write_smart_str, NULL, &str, encoding, XML_SAVE_AS_XML);
265+
xmlSaveCtxtPtr ctxt = xmlSaveToIO(php_new_dom_write_smart_str, NULL, &str, encoding, XML_SAVE_AS_XML | options);
266266
if (EXPECTED(ctxt != NULL)) {
267267
xmlCharEncodingHandlerPtr handler = xmlFindCharEncodingHandler(encoding);
268268
xmlOutputBufferPtr out = xmlOutputBufferCreateIO(php_new_dom_write_smart_str, NULL, &str, handler);
@@ -284,9 +284,14 @@ static zend_string *php_new_dom_dump_node_to_str(xmlDocPtr doc, xmlNodePtr node,
284284
return smart_str_extract(&str);
285285
}
286286

287+
static zend_string *php_new_dom_dump_node_to_str(xmlDocPtr doc, xmlNodePtr node, bool format, const char *encoding)
288+
{
289+
return php_new_dom_dump_node_to_str_ex(node, 0, format, encoding);
290+
}
291+
287292
static zend_string *php_new_dom_dump_doc_to_str(xmlDocPtr doc, int options, const char *encoding)
288293
{
289-
return php_new_dom_dump_node_to_str(doc, (xmlNodePtr) doc, options & XML_SAVE_FORMAT, encoding);
294+
return php_new_dom_dump_node_to_str_ex((xmlNodePtr) doc, options, options & XML_SAVE_FORMAT, encoding);
290295
}
291296

292297
zend_long php_new_dom_dump_node_to_file(const char *filename, xmlDocPtr doc, xmlNodePtr node, bool format, const char *encoding)

0 commit comments

Comments
 (0)