From 5baf2f3efc12e30eb3fb9fae16dc5cb85f86074f Mon Sep 17 00:00:00 2001 From: Daryll Doyle Date: Wed, 14 Feb 2024 17:20:12 +0000 Subject: [PATCH] Allow the enabling of loading large files --- src/Sanitizer.php | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/Sanitizer.php b/src/Sanitizer.php index b5d6dfe..60072fa 100644 --- a/src/Sanitizer.php +++ b/src/Sanitizer.php @@ -81,6 +81,11 @@ class Sanitizer */ protected $useNestingLimit = 15; + /** + * @var bool + */ + protected $allowHugeFiles = false; + /** * */ @@ -183,6 +188,24 @@ public function getXmlIssues() { return $this->xmlIssues; } + /** + * Can we allow huge files? + * + * @return bool + */ + public function getAllowHugeFiles() { + return $this->allowHugeFiles; + } + + /** + * Set whether we can allow huge files. + * + * @param bool $allowHugeFiles + */ + public function setAllowHugeFiles( $allowHugeFiles ) { + $this->allowHugeFiles = $allowHugeFiles; + } + /** * Sanitize the passed string @@ -203,7 +226,7 @@ public function sanitize($dirty) $this->resetInternal(); $this->setUpBefore(); - $loaded = $this->xmlDocument->loadXML($dirty); + $loaded = $this->xmlDocument->loadXML($dirty, $this->getAllowHugeFiles() ? LIBXML_PARSEHUGE : 0); // If we couldn't parse the XML then we go no further. Reset and return false if (!$loaded) {