Skip to content

Commit 03b3dfe

Browse files
committed
Only explicitly set encoding if not provided by the XML parser
1 parent 3a7c37c commit 03b3dfe

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
DOM\XMLDocument::createFromString 04
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
8+
$dom = DOM\XMLDocument::createFromString('<?xml version="1.0" encoding="Windows-1251"?><container/>');
9+
var_dump($dom->encoding);
10+
echo $dom->saveXML();
11+
12+
?>
13+
--EXPECT--
14+
string(12) "Windows-1251"
15+
<?xml version="1.0" encoding="Windows-1251"?>
16+
<container/>

ext/dom/xml_document.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,12 @@ static void load_from_helper(INTERNAL_FUNCTION_PARAMETERS, int mode)
228228
}
229229
RETURN_THROWS();
230230
}
231-
if (override_encoding) {
232-
lxml_doc->encoding = xmlStrdup((const xmlChar *) override_encoding);
233-
} else {
234-
lxml_doc->encoding = xmlStrdup((const xmlChar *) "UTF-8");
231+
if (lxml_doc->encoding == NULL) {
232+
if (override_encoding) {
233+
lxml_doc->encoding = xmlStrdup((const xmlChar *) override_encoding);
234+
} else {
235+
lxml_doc->encoding = xmlStrdup((const xmlChar *) "UTF-8");
236+
}
235237
}
236238
dom_object *intern = php_dom_instantiate_object_helper(
237239
return_value,

0 commit comments

Comments
 (0)