@@ -54,15 +54,24 @@ public function encode($data, $format)
54
54
*/
55
55
public function decode ($ data , $ format )
56
56
{
57
- $ this ->assertNoCustomDocType ($ data );
58
57
$ internalErrors = libxml_use_internal_errors (true );
59
58
$ disableEntities = libxml_disable_entity_loader (true );
60
59
libxml_clear_errors ();
61
60
62
- $ xml = simplexml_load_string ($ data );
61
+ $ dom = new \DOMDocument ();
62
+ $ dom ->loadXML ($ data );
63
+
63
64
libxml_use_internal_errors ($ internalErrors );
64
65
libxml_disable_entity_loader ($ disableEntities );
65
66
67
+ foreach ($ dom ->childNodes as $ child ) {
68
+ if ($ child ->nodeType === XML_DOCUMENT_TYPE_NODE ) {
69
+ throw new UnexpectedValueException ('Document types are not allowed. ' );
70
+ }
71
+ }
72
+
73
+ $ xml = simplexml_import_dom ($ dom );
74
+
66
75
if ($ error = libxml_get_last_error ()) {
67
76
throw new UnexpectedValueException ($ error ->message );
68
77
}
@@ -291,17 +300,6 @@ private function buildXml($parentNode, $data)
291
300
throw new UnexpectedValueException ('An unexpected value could not be serialized: ' .var_export ($ data , true ));
292
301
}
293
302
294
- private function assertNoCustomDocType ($ data )
295
- {
296
- $ dom = new \DOMDocument ;
297
- $ dom ->loadXML ($ data );
298
- foreach ($ dom ->childNodes as $ child ) {
299
- if ($ child ->nodeType === XML_DOCUMENT_TYPE_NODE ) {
300
- throw new \InvalidArgumentException ('Document types are not allowed. ' );
301
- }
302
- }
303
- }
304
-
305
303
/**
306
304
* Selects the type of node to create and appends it to the parent.
307
305
*
0 commit comments