Skip to content

Commit 727cb70

Browse files
committed
Ignore Settings::libXmlLoaderOptions
Backport of PR #4233.
1 parent c5f0f50 commit 727cb70

File tree

8 files changed

+52
-50
lines changed

8 files changed

+52
-50
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com)
66
and this project adheres to [Semantic Versioning](https://semver.org).
77

8+
## 1.29.5 - 2024-11-22
9+
10+
### Changed
11+
12+
- Settings::libXmlLoaderOptions is ignored. Backport of [PR #4233](https://github.com/PHPOffice/PhpSpreadsheet/pull/4233)
13+
14+
### Deprecated
15+
16+
- Settings::setLibXmlLoaderOptions() and Settings::getLibXmlLoaderOptions() are no longer needed - no replacement.
17+
818
## 1.29.4 - 2024-11-10
919

1020
### Fixed

docs/topics/reading-and-writing-to-file.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ versions of Microsoft Excel.
298298
**Excel 2003 XML limitations** Please note that Excel 2003 XML format
299299
has some limits regarding to styling cells and handling large
300300
spreadsheets via PHP.
301-
Also, only files using charset UTF-8 are supported.
302301

303302
### \PhpOffice\PhpSpreadsheet\Reader\Xml
304303

@@ -718,7 +717,7 @@ extension.
718717

719718
**HTML limitations** Please note that HTML file format has some limits
720719
regarding to styling cells, number formatting, ...
721-
Also, only files using charset UTF-8 are supported.
720+
Also, only files using ASCII characters, or charset UTF-8 (without BOM) are supported.
722721

723722
### \PhpOffice\PhpSpreadsheet\Reader\Html
724723

@@ -733,7 +732,7 @@ $spreadsheet = $reader->load("05featuredemo.html");
733732
```
734733

735734
**HTML limitations** Please note that HTML reader is still experimental
736-
and does not yet support merged cells or nested tables cleanly
735+
and does not yet support merged cells or nested tables cleanly.
737736

738737
### \PhpOffice\PhpSpreadsheet\Writer\Html
739738

src/PhpSpreadsheet/Reader/Gnumeric.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use PhpOffice\PhpSpreadsheet\Reader\Security\XmlScanner;
1212
use PhpOffice\PhpSpreadsheet\ReferenceHelper;
1313
use PhpOffice\PhpSpreadsheet\RichText\RichText;
14-
use PhpOffice\PhpSpreadsheet\Settings;
1514
use PhpOffice\PhpSpreadsheet\Shared\File;
1615
use PhpOffice\PhpSpreadsheet\Spreadsheet;
1716
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
@@ -114,7 +113,7 @@ public function listWorksheetNames($filename)
114113

115114
$xml = new XMLReader();
116115
$contents = $this->gzfileGetContents($filename);
117-
$xml->xml($contents, null, Settings::getLibXmlLoaderOptions());
116+
$xml->xml($contents);
118117
$xml->setParserProperty(2, true);
119118

120119
$worksheetNames = [];
@@ -147,7 +146,7 @@ public function listWorksheetInfo($filename)
147146

148147
$xml = new XMLReader();
149148
$contents = $this->gzfileGetContents($filename);
150-
$xml->xml($contents, null, Settings::getLibXmlLoaderOptions());
149+
$xml->xml($contents);
151150
$xml->setParserProperty(2, true);
152151

153152
$worksheetInfo = [];
@@ -267,7 +266,7 @@ public function loadIntoExisting(string $filename, Spreadsheet $spreadsheet): Sp
267266

268267
$gFileData = $this->gzfileGetContents($filename);
269268

270-
$xml2 = simplexml_load_string($gFileData, 'SimpleXMLElement', Settings::getLibXmlLoaderOptions());
269+
$xml2 = simplexml_load_string($gFileData);
271270
$xml = self::testSimpleXml($xml2);
272271

273272
$gnmXML = $xml->children(self::NAMESPACE_GNM);

src/PhpSpreadsheet/Reader/Ods.php

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use PhpOffice\PhpSpreadsheet\Reader\Ods\Properties as DocumentProperties;
1717
use PhpOffice\PhpSpreadsheet\Reader\Security\XmlScanner;
1818
use PhpOffice\PhpSpreadsheet\RichText\RichText;
19-
use PhpOffice\PhpSpreadsheet\Settings;
2019
use PhpOffice\PhpSpreadsheet\Shared\Date;
2120
use PhpOffice\PhpSpreadsheet\Shared\File;
2221
use PhpOffice\PhpSpreadsheet\Spreadsheet;
@@ -57,9 +56,12 @@ public function canRead(string $filename): bool
5756
$mimeType = $zip->getFromName($stat['name']);
5857
} elseif ($zip->statName('META-INF/manifest.xml')) {
5958
$xml = simplexml_load_string(
60-
$this->getSecurityScannerOrThrow()->scan($zip->getFromName('META-INF/manifest.xml')),
61-
'SimpleXMLElement',
62-
Settings::getLibXmlLoaderOptions()
59+
$this->getSecurityScannerOrThrow()
60+
->scan(
61+
$zip->getFromName(
62+
'META-INF/manifest.xml'
63+
)
64+
)
6365
);
6466
if ($xml !== false) {
6567
$namespacesContent = $xml->getNamespaces(true);
@@ -100,9 +102,8 @@ public function listWorksheetNames($filename)
100102

101103
$xml = new XMLReader();
102104
$xml->xml(
103-
$this->getSecurityScannerOrThrow()->scanFile('zip://' . realpath($filename) . '#' . self::INITIAL_FILE),
104-
null,
105-
Settings::getLibXmlLoaderOptions()
105+
$this->getSecurityScannerOrThrow()
106+
->scanFile('zip://' . realpath($filename) . '#' . self::INITIAL_FILE)
106107
);
107108
$xml->setParserProperty(2, true);
108109

@@ -151,9 +152,8 @@ public function listWorksheetInfo($filename)
151152

152153
$xml = new XMLReader();
153154
$xml->xml(
154-
$this->getSecurityScannerOrThrow()->scanFile('zip://' . realpath($filename) . '#' . self::INITIAL_FILE),
155-
null,
156-
Settings::getLibXmlLoaderOptions()
155+
$this->getSecurityScannerOrThrow()
156+
->scanFile('zip://' . realpath($filename) . '#' . self::INITIAL_FILE)
157157
);
158158
$xml->setParserProperty(2, true);
159159

@@ -262,9 +262,8 @@ public function loadIntoExisting($filename, Spreadsheet $spreadsheet)
262262
// Meta
263263

264264
$xml = @simplexml_load_string(
265-
$this->getSecurityScannerOrThrow()->scan($zip->getFromName('meta.xml')),
266-
'SimpleXMLElement',
267-
Settings::getLibXmlLoaderOptions()
265+
$this->getSecurityScannerOrThrow()
266+
->scan($zip->getFromName('meta.xml'))
268267
);
269268
if ($xml === false) {
270269
throw new Exception('Unable to read data from {$pFilename}');
@@ -278,8 +277,8 @@ public function loadIntoExisting($filename, Spreadsheet $spreadsheet)
278277

279278
$dom = new DOMDocument('1.01', 'UTF-8');
280279
$dom->loadXML(
281-
$this->getSecurityScannerOrThrow()->scan($zip->getFromName('styles.xml')),
282-
Settings::getLibXmlLoaderOptions()
280+
$this->getSecurityScannerOrThrow()
281+
->scan($zip->getFromName('styles.xml'))
283282
);
284283

285284
$pageSettings = new PageSettings($dom);
@@ -288,8 +287,8 @@ public function loadIntoExisting($filename, Spreadsheet $spreadsheet)
288287

289288
$dom = new DOMDocument('1.01', 'UTF-8');
290289
$dom->loadXML(
291-
$this->getSecurityScannerOrThrow()->scan($zip->getFromName(self::INITIAL_FILE)),
292-
Settings::getLibXmlLoaderOptions()
290+
$this->getSecurityScannerOrThrow()
291+
->scan($zip->getFromName(self::INITIAL_FILE))
293292
);
294293

295294
$officeNs = $dom->lookupNamespaceUri('office');
@@ -664,8 +663,8 @@ private function processSettings(ZipArchive $zip, Spreadsheet $spreadsheet): voi
664663
{
665664
$dom = new DOMDocument('1.01', 'UTF-8');
666665
$dom->loadXML(
667-
$this->getSecurityScannerOrThrow()->scan($zip->getFromName('settings.xml')),
668-
Settings::getLibXmlLoaderOptions()
666+
$this->getSecurityScannerOrThrow()
667+
->scan($zip->getFromName('settings.xml'))
669668
);
670669
//$xlinkNs = $dom->lookupNamespaceUri('xlink');
671670
$configNs = $dom->lookupNamespaceUri('config');

src/PhpSpreadsheet/Reader/Xlsx.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
use PhpOffice\PhpSpreadsheet\Reader\Xlsx\WorkbookView;
2626
use PhpOffice\PhpSpreadsheet\ReferenceHelper;
2727
use PhpOffice\PhpSpreadsheet\RichText\RichText;
28-
use PhpOffice\PhpSpreadsheet\Settings;
2928
use PhpOffice\PhpSpreadsheet\Shared\Date;
3029
use PhpOffice\PhpSpreadsheet\Shared\Drawing;
3130
use PhpOffice\PhpSpreadsheet\Shared\File;
@@ -137,7 +136,7 @@ private function loadZip(string $filename, string $ns = '', bool $replaceUnclose
137136
$rels = @simplexml_load_string(
138137
$this->getSecurityScannerOrThrow()->scan($contents),
139138
'SimpleXMLElement',
140-
Settings::getLibXmlLoaderOptions(),
139+
0,
141140
$ns
142141
);
143142

@@ -152,7 +151,7 @@ private function loadZipNonamespace(string $filename, string $ns): SimpleXMLElem
152151
$rels = simplexml_load_string(
153152
$this->getSecurityScannerOrThrow()->scan($contents),
154153
'SimpleXMLElement',
155-
Settings::getLibXmlLoaderOptions(),
154+
0,
156155
($ns === '' ? $ns : '')
157156
);
158157

@@ -268,11 +267,13 @@ public function listWorksheetInfo($filename)
268267

269268
$xml = new XMLReader();
270269
$xml->xml(
271-
$this->getSecurityScannerOrThrow()->scan(
272-
$this->getFromZipArchive($this->zip, $fileWorksheetPath)
273-
),
274-
null,
275-
Settings::getLibXmlLoaderOptions()
270+
$this->getSecurityScannerOrThrow()
271+
->scan(
272+
$this->getFromZipArchive(
273+
$this->zip,
274+
$fileWorksheetPath
275+
)
276+
)
276277
);
277278
$xml->setParserProperty(2, true);
278279

@@ -1940,9 +1941,8 @@ private function readRibbon(Spreadsheet $excel, string $customUITarget, ZipArchi
19401941
if ($dataRels) {
19411942
// exists and not empty if the ribbon have some pictures (other than internal MSO)
19421943
$UIRels = simplexml_load_string(
1943-
$this->getSecurityScannerOrThrow()->scan($dataRels),
1944-
'SimpleXMLElement',
1945-
Settings::getLibXmlLoaderOptions()
1944+
$this->getSecurityScannerOrThrow()
1945+
->scan($dataRels)
19461946
);
19471947
if (false !== $UIRels) {
19481948
// we need to save id and target to avoid parsing customUI.xml and "guess" if it's a pseudo callback who load the image

src/PhpSpreadsheet/Reader/Xlsx/Properties.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use PhpOffice\PhpSpreadsheet\Document\Properties as DocumentProperties;
66
use PhpOffice\PhpSpreadsheet\Reader\Security\XmlScanner;
7-
use PhpOffice\PhpSpreadsheet\Settings;
87
use SimpleXMLElement;
98

109
class Properties
@@ -33,9 +32,7 @@ private function extractPropertyData(string $propertyData): ?SimpleXMLElement
3332
{
3433
// okay to omit namespace because everything will be processed by xpath
3534
$obj = simplexml_load_string(
36-
$this->securityScanner->scan($propertyData),
37-
'SimpleXMLElement',
38-
Settings::getLibXmlLoaderOptions()
35+
$this->securityScanner->scan($propertyData)
3936
);
4037

4138
return self::nullOrSimple($obj);

src/PhpSpreadsheet/Reader/Xml.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use PhpOffice\PhpSpreadsheet\Reader\Xml\Properties;
1515
use PhpOffice\PhpSpreadsheet\Reader\Xml\Style;
1616
use PhpOffice\PhpSpreadsheet\RichText\RichText;
17-
use PhpOffice\PhpSpreadsheet\Settings;
1817
use PhpOffice\PhpSpreadsheet\Shared\Date;
1918
use PhpOffice\PhpSpreadsheet\Shared\File;
2019
use PhpOffice\PhpSpreadsheet\Spreadsheet;
@@ -105,9 +104,8 @@ public function trySimpleXMLLoadString($filename)
105104
{
106105
try {
107106
$xml = simplexml_load_string(
108-
$this->getSecurityScannerOrThrow()->scan($this->fileContents ?: file_get_contents($filename)),
109-
'SimpleXMLElement',
110-
Settings::getLibXmlLoaderOptions()
107+
$this->getSecurityScannerOrThrow()
108+
->scan($this->fileContents ?: file_get_contents($filename))
111109
);
112110
} catch (\Exception $e) {
113111
throw new Exception('Cannot load invalid XML file: ' . $filename, 0, $e);

src/PhpSpreadsheet/Settings.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ public static function htmlEntityFlags(): int
9898
* Set default options for libxml loader.
9999
*
100100
* @param ?int $options Default options for libxml loader
101+
*
102+
* @deprecated 3.5.0 no longer needed
101103
*/
102104
public static function setLibXmlLoaderOptions($options): int
103105
{
@@ -114,14 +116,12 @@ public static function setLibXmlLoaderOptions($options): int
114116
* Defaults to LIBXML_DTDLOAD | LIBXML_DTDATTR when not set explicitly.
115117
*
116118
* @return int Default options for libxml loader
119+
*
120+
* @deprecated 3.5.0 no longer needed
117121
*/
118122
public static function getLibXmlLoaderOptions(): int
119123
{
120-
if (self::$libXmlLoaderOptions === null) {
121-
return self::setLibXmlLoaderOptions(null);
122-
}
123-
124-
return self::$libXmlLoaderOptions;
124+
return self::$libXmlLoaderOptions ?? (defined('LIBXML_DTDLOAD') ? (LIBXML_DTDLOAD | LIBXML_DTDATTR) : 0);
125125
}
126126

127127
/**

0 commit comments

Comments
 (0)