From 481cef2def54226368b35ea9de3867fac8101f33 Mon Sep 17 00:00:00 2001 From: oleibman <10341515+oleibman@users.noreply.github.com> Date: Wed, 15 Jun 2022 18:47:35 -0700 Subject: [PATCH] Php8.2 Deprecation in Reader/Xlsx (#2894) * Php8.2 Deprecation in Reader/Xlsx Using `${var}` will be deprecated, with the suggested resolution being to use `{$var}`. This appears to be the only place in PhpSpreadsheet which does this. Some vendor packages will need to change for 8.2 for this and other reasons. * mb_convert_encoding and HTML_ENTITIES Also scheduled to be deprecated with 8.2. It appears to have not been needed in PhpSpreadsheet in the first place. --- src/PhpSpreadsheet/Reader/Html.php | 18 ++++-------------- src/PhpSpreadsheet/Reader/Xlsx.php | 7 +------ 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/src/PhpSpreadsheet/Reader/Html.php b/src/PhpSpreadsheet/Reader/Html.php index 4edf3cf8..3d859e15 100644 --- a/src/PhpSpreadsheet/Reader/Html.php +++ b/src/PhpSpreadsheet/Reader/Html.php @@ -632,16 +632,6 @@ class Html extends BaseReader } } - /** - * Make sure mb_convert_encoding returns string. - * - * @param mixed $result - */ - private static function ensureString($result): string - { - return is_string($result) ? $result : ''; - } - /** * Loads PhpSpreadsheet from file into PhpSpreadsheet instance. * @@ -660,8 +650,8 @@ class Html extends BaseReader $dom = new DOMDocument(); // Reload the HTML file into the DOM object try { - $convert = mb_convert_encoding($this->securityScanner->scanFile($filename), 'HTML-ENTITIES', 'UTF-8'); - $loaded = $dom->loadHTML(self::ensureString($convert)); + $convert = $this->securityScanner->scanFile($filename); + $loaded = $dom->loadHTML($convert); } catch (Throwable $e) { $loaded = false; } @@ -683,8 +673,8 @@ class Html extends BaseReader $dom = new DOMDocument(); // Reload the HTML file into the DOM object try { - $convert = mb_convert_encoding($this->securityScanner->scan($content), 'HTML-ENTITIES', 'UTF-8'); - $loaded = $dom->loadHTML(self::ensureString($convert)); + $convert = $this->securityScanner->scan($content); + $loaded = $dom->loadHTML($convert); } catch (Throwable $e) { $loaded = false; } diff --git a/src/PhpSpreadsheet/Reader/Xlsx.php b/src/PhpSpreadsheet/Reader/Xlsx.php index 8562339b..52df94e4 100644 --- a/src/PhpSpreadsheet/Reader/Xlsx.php +++ b/src/PhpSpreadsheet/Reader/Xlsx.php @@ -414,7 +414,7 @@ class Xlsx extends BaseReader [$workbookBasename, $xmlNamespaceBase] = $this->getWorkbookBaseName(); $drawingNS = self::REL_TO_DRAWING[$xmlNamespaceBase] ?? Namespaces::DRAWINGML; $chartNS = self::REL_TO_CHART[$xmlNamespaceBase] ?? Namespaces::CHART; - $wbRels = $this->loadZip("xl/_rels/${workbookBasename}.rels", Namespaces::RELATIONSHIPS); + $wbRels = $this->loadZip("xl/_rels/{$workbookBasename}.rels", Namespaces::RELATIONSHIPS); $theme = null; $this->styleReader = new Styles(); foreach ($wbRels->Relationship as $relx) { @@ -1849,11 +1849,6 @@ class Xlsx extends BaseReader private static function dirAdd($base, $add): string { - $add = "$add"; - if (substr($add, 0, 4) === '/xl/') { - $add = substr($add, 4); - } - return (string) preg_replace('~[^/]+/\.\./~', '', dirname($base) . "/$add"); }