Skip to content

Commit 388508d

Browse files
authored
Backport of 'do not trigger Undefined array key "x"'. (#4679)
* Backport of 'do not trigger `Undefined array key "x"`'. [PR #4669](#4669) * Update CHANGELOG.md
1 parent 5bda298 commit 388508d

File tree

4 files changed

+111
-1
lines changed

4 files changed

+111
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). This is a
1010
### Fixed
1111

1212
- Php8.5 deprecates use of null as array index. [PR #4636](https://github.com/PHPOffice/PhpSpreadsheet/pull/4636)
13+
- Fix 'do not trigger `Undefined array key "x"`'. [Issue #4668](https://github.com/PHPOffice/PhpSpreadsheet/issues/4668) [PR #4679](https://github.com/PHPOffice/PhpSpreadsheet/pull/4679) Backport of [PR #4669](https://github.com/PHPOffice/PhpSpreadsheet/pull/4669)
1314

1415
## 2025-09-03 - 3.10.1
1516

src/PhpSpreadsheet/Reader/Xml/Style.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function parseStyles(SimpleXMLElement $xml, array $namespaces): array
6868
break;
6969
case 'Protection':
7070
$locked = $hidden = null;
71-
$styleAttributesP = $styleData->attributes($namespaces['x']);
71+
$styleAttributesP = array_key_exists('x', $namespaces) ? $styleData->attributes($namespaces['x']) : [];
7272
if (isset($styleAttributes['Protected'])) {
7373
$locked = ((bool) (string) $styleAttributes['Protected']) ? Protection::PROTECTION_PROTECTED : Protection::PROTECTION_UNPROTECTED;
7474
}

tests/PhpSpreadsheetTests/Reader/Xml/XmlTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xml;
66

77
use PhpOffice\PhpSpreadsheet\Cell\DataType;
8+
use PhpOffice\PhpSpreadsheet\IOFactory;
89
use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException;
910
use PhpOffice\PhpSpreadsheet\Reader\Xml;
1011
use PHPUnit\Framework\TestCase;
@@ -103,4 +104,24 @@ public function testEmptyFilename(): void
103104
$this->expectExceptionMessage('File "" does not exist');
104105
$xmlReader->load('');
105106
}
107+
108+
/**
109+
* Ensures that a PHP warning for `Undefined array key "x"` is not triggered.
110+
*
111+
* Relies on PHPUnit's conversion of PHP warnings, deprecations, and notices to exceptions.
112+
* If that warning occurs, the test should fail.
113+
*/
114+
public function testLoadXlsBug4669(): void
115+
{
116+
$filename = 'tests/data/Reader/Xml/bug4669.xml';
117+
118+
$reader = IOFactory::createReaderForFile($filename);
119+
$reader->setReadDataOnly(true);
120+
121+
$spreadsheet = $reader->load($filename);
122+
123+
$sheet = $spreadsheet->getActiveSheet();
124+
self::assertSame('Report Date', $sheet->getCell('A1')->getValue());
125+
$spreadsheet->disconnectWorksheets();
126+
}
106127
}

tests/data/Reader/Xml/bug4669.xml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
3+
<Styles>
4+
<Style ss:ID="Default" ss:Name="Normal">
5+
<Alignment ss:Vertical="Bottom"/>
6+
<Borders/>
7+
<Font ss:FontName="Verdana"/>
8+
<Interior/>
9+
<NumberFormat/>
10+
<Protection/>
11+
</Style>
12+
<Style ss:ID="s22">
13+
<NumberFormat ss:Format="General Date"/>
14+
</Style>
15+
<Style ss:ID="s66">
16+
<NumberFormat ss:Format="Fixed"/>
17+
</Style>
18+
</Styles>
19+
<Worksheet ss:Name="stats by transaction_notes">
20+
<Table>
21+
<Row>
22+
<Cell ss:StyleID="Default">
23+
<Data ss:Type="String">Report Date</Data>
24+
</Cell>
25+
<Cell ss:StyleID="Default">
26+
<Data ss:Type="String">Trx Date</Data>
27+
</Cell>
28+
<Cell ss:StyleID="Default">
29+
<Data ss:Type="String">Merchant</Data>
30+
</Cell>
31+
<Cell ss:StyleID="Default">
32+
<Data ss:Type="String">Terminal</Data>
33+
</Cell>
34+
<Cell ss:StyleID="Default">
35+
<Data ss:Type="String">Report Type</Data>
36+
</Cell>
37+
<Cell ss:StyleID="Default">
38+
<Data ss:Type="String">Transition</Data>
39+
</Cell>
40+
<Cell ss:StyleID="Default">
41+
<Data ss:Type="String">Report Message</Data>
42+
</Cell>
43+
<Cell ss:StyleID="Default">
44+
<Data ss:Type="String">Report Info</Data>
45+
</Cell>
46+
<Cell ss:StyleID="Default">
47+
<Data ss:Type="String">Status</Data>
48+
</Cell>
49+
<Cell ss:StyleID="Default">
50+
<Data ss:Type="String">Merchant Transaction ID</Data>
51+
</Cell>
52+
<Cell ss:StyleID="Default">
53+
<Data ss:Type="String">Unique ID</Data>
54+
</Cell>
55+
<Cell ss:StyleID="Default">
56+
<Data ss:Type="String">Reference Transaction ID</Data>
57+
</Cell>
58+
<Cell ss:StyleID="Default">
59+
<Data ss:Type="String">Reference Transaction Type</Data>
60+
</Cell>
61+
<Cell ss:StyleID="Default">
62+
<Data ss:Type="String">Currency</Data>
63+
</Cell>
64+
<Cell ss:StyleID="Default">
65+
<Data ss:Type="String">Amount (in minor currency unit)</Data>
66+
</Cell>
67+
<Cell ss:StyleID="Default">
68+
<Data ss:Type="String">Card Holder</Data>
69+
</Cell>
70+
<Cell ss:StyleID="Default">
71+
<Data ss:Type="String">Card Brand</Data>
72+
</Cell>
73+
<Cell ss:StyleID="Default">
74+
<Data ss:Type="String">Card Number</Data>
75+
</Cell>
76+
<Cell ss:StyleID="Default">
77+
<Data ss:Type="String">Email</Data>
78+
</Cell>
79+
<Cell ss:StyleID="Default">
80+
<Data ss:Type="String">Country</Data>
81+
</Cell>
82+
<Cell ss:StyleID="Default">
83+
<Data ss:Type="String">Remote IP</Data>
84+
</Cell>
85+
</Row>
86+
</Table>
87+
</Worksheet>
88+
</Workbook>

0 commit comments

Comments
 (0)