From 34eaecf30ddff69d2a7a0144c813d691d4265705 Mon Sep 17 00:00:00 2001 From: Owen Leibman Date: Wed, 7 Jul 2021 14:44:15 -0700 Subject: [PATCH 1/2] Xls Reader Handle MACCENTRALEUROPE With or Without Hyphen Fixes issue #549 and https://github.com/Maatwebsite/Laravel-Excel/issues/989 (which is the source of the new test file). Some systems accept MACCENTRALEUROPE as the name for the appropriate encoding, and some accept MAC-CENTRALEUROPE. I fortunately have access to at least one of each type, and have run the tests on each. CodePage.php has an array of translations from codepage number to string. I now allow the value to itself be an array; if so, the code will test each in turn to see if it can be used in iconv. I did not go fishing for other similar problems. If such show up, they can be dealt with in the same manner as this one. I don't really expect others, since this is a problem not merely for Xls, but, even then, it applies only to BIFF5 and earlier. I also moved XlsTest from Reader to Reader/Xls. --- phpstan-baseline.neon | 15 ----------- src/PhpSpreadsheet/Shared/CodePage.php | 24 +++++++++++++----- .../Reader/{ => Xls}/XlsTest.php | 21 +++++++++++++-- .../Shared/CodePageTest.php | 9 ++++++- tests/data/Reader/XLS/maccentraleurope.xls | Bin 0 -> 20480 bytes tests/data/Shared/CodePage.php | 7 ++++- 6 files changed, 51 insertions(+), 25 deletions(-) rename tests/PhpSpreadsheetTests/Reader/{ => Xls}/XlsTest.php (79%) create mode 100644 tests/data/Reader/XLS/maccentraleurope.xls diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 3538d091c1..edf85c78bb 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -3775,11 +3775,6 @@ parameters: count: 1 path: src/PhpSpreadsheet/Settings.php - - - message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\CodePage\\:\\:\\$pageArray has no typehint specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Shared/CodePage.php - - message: "#^Parameter \\#1 \\$dateValue of static method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Date\\:\\:timestampToExcel\\(\\) expects int, float\\|int\\|string given\\.$#" count: 1 @@ -6810,16 +6805,6 @@ parameters: count: 1 path: tests/PhpSpreadsheetTests/Reader/Security/XmlScannerTest.php - - - message: "#^Cannot call method getFormattedValue\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Cell\\\\Cell\\|null\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/Reader/XlsTest.php - - - - message: "#^Cannot call method getCoordinate\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Cell\\\\Cell\\|null\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/Reader/XlsTest.php - - message: "#^Method PhpOffice\\\\PhpSpreadsheetTests\\\\Reader\\\\Xlsx\\\\AutoFilterTest\\:\\:getWorksheetInstance\\(\\) has no return typehint specified\\.$#" count: 1 diff --git a/src/PhpSpreadsheet/Shared/CodePage.php b/src/PhpSpreadsheet/Shared/CodePage.php index 1d5d8933ed..8d406f64b9 100644 --- a/src/PhpSpreadsheet/Shared/CodePage.php +++ b/src/PhpSpreadsheet/Shared/CodePage.php @@ -8,7 +8,7 @@ class CodePage { public const DEFAULT_CODE_PAGE = 'CP1252'; - private static $pageArray = [ + private const PAGE_ARRAY = [ 0 => 'CP1252', // CodePage is not always correctly set when the xls file was saved by Apple's Numbers program 367 => 'ASCII', // ASCII 437 => 'CP437', // OEM US @@ -56,7 +56,7 @@ class CodePage 10010 => 'MACROMANIA', // Macintosh Romania 10017 => 'MACUKRAINE', // Macintosh Ukraine 10021 => 'MACTHAI', // Macintosh Thai - 10029 => 'MACCENTRALEUROPE', // Macintosh Central Europe + 10029 => ['MACCENTRALEUROPE', 'MAC-CENTRALEUROPE'], // Macintosh Central Europe 10079 => 'MACICELAND', // Macintosh Icelandic 10081 => 'MACTURKISH', // Macintosh Turkish 10082 => 'MACCROATIAN', // Macintosh Croatian @@ -65,11 +65,12 @@ class CodePage //32769 => 'unsupported', // ANSI Latin I (BIFF2-BIFF3) 65000 => 'UTF-7', // Unicode (UTF-7) 65001 => 'UTF-8', // Unicode (UTF-8) + 99999 => ['unsupported'], // Unicode (UTF-8) ]; public static function validate(string $codePage): bool { - return in_array($codePage, self::$pageArray, true); + return in_array($codePage, self::PAGE_ARRAY, true); } /** @@ -82,8 +83,19 @@ public static function validate(string $codePage): bool */ public static function numberToName(int $codePage): string { - if (array_key_exists($codePage, self::$pageArray)) { - return self::$pageArray[$codePage]; + if (array_key_exists($codePage, self::PAGE_ARRAY)) { + $value = self::PAGE_ARRAY[$codePage]; + if (is_array($value)) { + foreach ($value as $encoding) { + if (@iconv('UTF-8', $encoding, ' ') !== false) { + return $encoding; + } + } + + throw new PhpSpreadsheetException("Code page $codePage not implemented on this system."); + } else { + return $value; + } } if ($codePage == 720 || $codePage == 32769) { throw new PhpSpreadsheetException("Code page $codePage not supported."); // OEM Arabic @@ -94,6 +106,6 @@ public static function numberToName(int $codePage): string public static function getEncodings(): array { - return self::$pageArray; + return self::PAGE_ARRAY; } } diff --git a/tests/PhpSpreadsheetTests/Reader/XlsTest.php b/tests/PhpSpreadsheetTests/Reader/Xls/XlsTest.php similarity index 79% rename from tests/PhpSpreadsheetTests/Reader/XlsTest.php rename to tests/PhpSpreadsheetTests/Reader/Xls/XlsTest.php index 130374b359..b1091c8d60 100644 --- a/tests/PhpSpreadsheetTests/Reader/XlsTest.php +++ b/tests/PhpSpreadsheetTests/Reader/Xls/XlsTest.php @@ -1,7 +1,8 @@ getRowIterator(); foreach ($rowIterator as $row) { - foreach ($row->getCellIterator() as $cell) { + foreach ($row->getCellIterator() as $cellx) { + /** @var Cell */ + $cell = $cellx; $valOld = $cell->getFormattedValue(); $valNew = $newsheet->getCell($cell->getCoordinate())->getFormattedValue(); self::assertEquals($valOld, $valNew); } } } + + /** + * Test load Xls file with MACCENTRALEUROPE encoding, which is implemented + * as MAC-CENTRALEUROPE on some systems. Issue #549. + */ + public function testLoadMacCentralEurope(): void + { + $filename = 'tests/data/Reader/XLS/maccentraleurope.xls'; + $reader = new Xls(); + // When no fix applied, spreadsheet fails to load on some systems + $spreadsheet = $reader->load($filename); + $sheet = $spreadsheet->getActiveSheet(); + self::assertSame('Ładowność', $sheet->getCell('I1')->getValue()); + } } diff --git a/tests/PhpSpreadsheetTests/Shared/CodePageTest.php b/tests/PhpSpreadsheetTests/Shared/CodePageTest.php index e7dc7469d1..af036f4ed4 100644 --- a/tests/PhpSpreadsheetTests/Shared/CodePageTest.php +++ b/tests/PhpSpreadsheetTests/Shared/CodePageTest.php @@ -16,8 +16,15 @@ class CodePageTest extends TestCase */ public function testCodePageNumberToName($expectedResult, $codePageIndex): void { + if ($expectedResult === 'exception') { + $this->expectException(Exception::class); + } $result = CodePage::numberToName($codePageIndex); - self::assertEquals($expectedResult, $result); + if (is_array($expectedResult)) { + self::assertContains($result, $expectedResult); + } else { + self::assertEquals($expectedResult, $result); + } } public function providerCodePage(): array diff --git a/tests/data/Reader/XLS/maccentraleurope.xls b/tests/data/Reader/XLS/maccentraleurope.xls new file mode 100644 index 0000000000000000000000000000000000000000..98607556ee23184827685ca3787bbd060b06222e GIT binary patch literal 20480 zcmeG^2UHZk-0rTrbt~PvxreGt<`35GZCOJUu3kio z)QRgu@|3Ys3%c>eqgz%RRbrDEX;F(IYp$3|MSwX}|jb}kI4jb=;9H;N3FY{pT zRd@GV2c_MhIsll*kda{^J(VPqC|Zw1S@I^mTM!n7aVyoKDTPq9nLk6RLn259Nrt~j z+V%n91p%!SV$w-Gyr*bj>ICvB$jA1BI%pu3%epCnbVvY5h^BSm(>3tt^zj1uQrnv< zAN_S#B43{ktyouw+)fnf-OSS>y3p`z2#f5|J^^<^9zq&L#$($L&EltUg8A`L$&o2p zplUo+8;69zGa6hcBx#TYbSQn3?#<}? zZkncyp``mF5tTRhjf)ph;P^D07?B# z#a-}5gG5z4&~kIeHySLrY?Pu$qZGXwp`eIwy>C=&N)eAnC!ueS{`k+eW8DDLnu4q4AV6`;s%YGL)w!Z(wk~e#*&Vt zJ7An3M^*kP$ZxAX044L~Z9yN(`$p>c#y#W<4PHIx2Gu$@MKxvH8dFVm z3C3fxswvYksy(3R#e{qmbLy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Shared/CodePage.php | 13 ++++++---- .../Reader/Xls/XlsTest.php | 26 +++++++++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/PhpSpreadsheet/Shared/CodePage.php b/src/PhpSpreadsheet/Shared/CodePage.php index 8d406f64b9..8718a6135e 100644 --- a/src/PhpSpreadsheet/Shared/CodePage.php +++ b/src/PhpSpreadsheet/Shared/CodePage.php @@ -8,7 +8,8 @@ class CodePage { public const DEFAULT_CODE_PAGE = 'CP1252'; - private const PAGE_ARRAY = [ + /** @var array */ + private static $pageArray = [ 0 => 'CP1252', // CodePage is not always correctly set when the xls file was saved by Apple's Numbers program 367 => 'ASCII', // ASCII 437 => 'CP437', // OEM US @@ -70,7 +71,7 @@ class CodePage public static function validate(string $codePage): bool { - return in_array($codePage, self::PAGE_ARRAY, true); + return in_array($codePage, self::$pageArray, true); } /** @@ -83,11 +84,13 @@ public static function validate(string $codePage): bool */ public static function numberToName(int $codePage): string { - if (array_key_exists($codePage, self::PAGE_ARRAY)) { - $value = self::PAGE_ARRAY[$codePage]; + if (array_key_exists($codePage, self::$pageArray)) { + $value = self::$pageArray[$codePage]; if (is_array($value)) { foreach ($value as $encoding) { if (@iconv('UTF-8', $encoding, ' ') !== false) { + self::$pageArray[$codePage] = $encoding; + return $encoding; } } @@ -106,6 +109,6 @@ public static function numberToName(int $codePage): string public static function getEncodings(): array { - return self::PAGE_ARRAY; + return self::$pageArray; } } diff --git a/tests/PhpSpreadsheetTests/Reader/Xls/XlsTest.php b/tests/PhpSpreadsheetTests/Reader/Xls/XlsTest.php index b1091c8d60..942576948a 100644 --- a/tests/PhpSpreadsheetTests/Reader/Xls/XlsTest.php +++ b/tests/PhpSpreadsheetTests/Reader/Xls/XlsTest.php @@ -4,6 +4,7 @@ use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Reader\Xls; +use PhpOffice\PhpSpreadsheet\Shared\CodePage; use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; class XlsTest extends AbstractFunctional @@ -17,6 +18,7 @@ public function testLoadXlsSample(): void $reader = new Xls(); $spreadsheet = $reader->load($filename); self::assertEquals('Title', $spreadsheet->getSheet(0)->getCell('A1')->getValue()); + $spreadsheet->disconnectWorksheets(); } /** @@ -43,6 +45,8 @@ public function testLoadXlsBug1505(): void self::assertEquals($row, $newrow); self::assertEquals($sheet->getCell('A1')->getFormattedValue(), $newsheet->getCell('A1')->getFormattedValue()); self::assertEquals($sheet->getCell("$col$row")->getFormattedValue(), $newsheet->getCell("$col$row")->getFormattedValue()); + $spreadsheet->disconnectWorksheets(); + $newspreadsheet->disconnectWorksheets(); } /** @@ -80,6 +84,8 @@ public function testLoadXlsBug1592(): void self::assertEquals($valOld, $valNew); } } + $spreadsheet->disconnectWorksheets(); + $newspreadsheet->disconnectWorksheets(); } /** @@ -88,11 +94,31 @@ public function testLoadXlsBug1592(): void */ public function testLoadMacCentralEurope(): void { + $codePages = CodePage::getEncodings(); + self::assertIsArray($codePages[10029]); $filename = 'tests/data/Reader/XLS/maccentraleurope.xls'; $reader = new Xls(); // When no fix applied, spreadsheet fails to load on some systems $spreadsheet = $reader->load($filename); $sheet = $spreadsheet->getActiveSheet(); self::assertSame('Ładowność', $sheet->getCell('I1')->getValue()); + $spreadsheet->disconnectWorksheets(); + } + + /** + * First test changes array entry in CodePage. + * This test confirms new that new entry is okay. + */ + public function testLoadMacCentralEurope2(): void + { + $codePages = CodePage::getEncodings(); + self::assertIsString($codePages[10029]); + $filename = 'tests/data/Reader/XLS/maccentraleurope.xls'; + $reader = new Xls(); + // When no fix applied, spreadsheet fails to load on some systems + $spreadsheet = $reader->load($filename); + $sheet = $spreadsheet->getActiveSheet(); + self::assertSame('Ładowność', $sheet->getCell('I1')->getValue()); + $spreadsheet->disconnectWorksheets(); } }