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.
This commit is contained in:
oleibman 2022-06-15 18:47:35 -07:00 committed by GitHub
parent 1829dea91e
commit 481cef2def
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 20 deletions

View File

@ -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. * Loads PhpSpreadsheet from file into PhpSpreadsheet instance.
* *
@ -660,8 +650,8 @@ class Html extends BaseReader
$dom = new DOMDocument(); $dom = new DOMDocument();
// Reload the HTML file into the DOM object // Reload the HTML file into the DOM object
try { try {
$convert = mb_convert_encoding($this->securityScanner->scanFile($filename), 'HTML-ENTITIES', 'UTF-8'); $convert = $this->securityScanner->scanFile($filename);
$loaded = $dom->loadHTML(self::ensureString($convert)); $loaded = $dom->loadHTML($convert);
} catch (Throwable $e) { } catch (Throwable $e) {
$loaded = false; $loaded = false;
} }
@ -683,8 +673,8 @@ class Html extends BaseReader
$dom = new DOMDocument(); $dom = new DOMDocument();
// Reload the HTML file into the DOM object // Reload the HTML file into the DOM object
try { try {
$convert = mb_convert_encoding($this->securityScanner->scan($content), 'HTML-ENTITIES', 'UTF-8'); $convert = $this->securityScanner->scan($content);
$loaded = $dom->loadHTML(self::ensureString($convert)); $loaded = $dom->loadHTML($convert);
} catch (Throwable $e) { } catch (Throwable $e) {
$loaded = false; $loaded = false;
} }

View File

@ -414,7 +414,7 @@ class Xlsx extends BaseReader
[$workbookBasename, $xmlNamespaceBase] = $this->getWorkbookBaseName(); [$workbookBasename, $xmlNamespaceBase] = $this->getWorkbookBaseName();
$drawingNS = self::REL_TO_DRAWING[$xmlNamespaceBase] ?? Namespaces::DRAWINGML; $drawingNS = self::REL_TO_DRAWING[$xmlNamespaceBase] ?? Namespaces::DRAWINGML;
$chartNS = self::REL_TO_CHART[$xmlNamespaceBase] ?? Namespaces::CHART; $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; $theme = null;
$this->styleReader = new Styles(); $this->styleReader = new Styles();
foreach ($wbRels->Relationship as $relx) { foreach ($wbRels->Relationship as $relx) {
@ -1849,11 +1849,6 @@ class Xlsx extends BaseReader
private static function dirAdd($base, $add): string 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"); return (string) preg_replace('~[^/]+/\.\./~', '', dirname($base) . "/$add");
} }