Skip to content

Commit cfea6c0

Browse files
committed
refined previous commit
1 parent dc18faa commit cfea6c0

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

Encoder/XmlEncoder.php

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,24 @@ public function encode($data, $format)
5454
*/
5555
public function decode($data, $format)
5656
{
57-
$this->assertNoCustomDocType($data);
5857
$internalErrors = libxml_use_internal_errors(true);
5958
$disableEntities = libxml_disable_entity_loader(true);
6059
libxml_clear_errors();
6160

62-
$xml = simplexml_load_string($data);
61+
$dom = new \DOMDocument();
62+
$dom->loadXML($data);
63+
6364
libxml_use_internal_errors($internalErrors);
6465
libxml_disable_entity_loader($disableEntities);
6566

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+
6675
if ($error = libxml_get_last_error()) {
6776
throw new UnexpectedValueException($error->message);
6877
}
@@ -291,17 +300,6 @@ private function buildXml($parentNode, $data)
291300
throw new UnexpectedValueException('An unexpected value could not be serialized: '.var_export($data, true));
292301
}
293302

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-
305303
/**
306304
* Selects the type of node to create and appends it to the parent.
307305
*

0 commit comments

Comments
 (0)