From d5825a66822ce97d7d71478130b2f2b80f01a509 Mon Sep 17 00:00:00 2001 From: oleibman Date: Tue, 30 Nov 2021 07:39:50 -0800 Subject: [PATCH] Read Spreadsheet with # in Name (#2409) Fix #2405. Treat last, rather than first, `#` as separator between zip file name and member name, by finding it with strrpos rather than strpos. --- src/PhpSpreadsheet/Shared/File.php | 4 ++-- .../Reader/Xlsx/OctothorpeTest.php | 20 ++++++++++++++++++ tests/data/Reader/XLSX/octo#thorpe.xlsx | Bin 0 -> 8677 bytes 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 tests/PhpSpreadsheetTests/Reader/Xlsx/OctothorpeTest.php create mode 100644 tests/data/Reader/XLSX/octo#thorpe.xlsx diff --git a/src/PhpSpreadsheet/Shared/File.php b/src/PhpSpreadsheet/Shared/File.php index 293b15ca48..f2fe8caa83 100644 --- a/src/PhpSpreadsheet/Shared/File.php +++ b/src/PhpSpreadsheet/Shared/File.php @@ -56,8 +56,8 @@ public static function fileExists(string $filename): bool // doing the original file_exists on ZIP archives... if (strtolower(substr($filename, 0, 6)) == 'zip://') { // Open ZIP file and verify if the file exists - $zipFile = substr($filename, 6, strpos($filename, '#') - 6); - $archiveFile = substr($filename, strpos($filename, '#') + 1); + $zipFile = substr($filename, 6, strrpos($filename, '#') - 6); + $archiveFile = substr($filename, strrpos($filename, '#') + 1); if (self::validateZipFirst4($zipFile)) { $zip = new ZipArchive(); diff --git a/tests/PhpSpreadsheetTests/Reader/Xlsx/OctothorpeTest.php b/tests/PhpSpreadsheetTests/Reader/Xlsx/OctothorpeTest.php new file mode 100644 index 0000000000..a5c6f20878 --- /dev/null +++ b/tests/PhpSpreadsheetTests/Reader/Xlsx/OctothorpeTest.php @@ -0,0 +1,20 @@ +load($filename); + $sheet = $spreadsheet->getActiveSheet(); + self::assertSame('xyz', $sheet->getCell('A1')->getValue()); + $spreadsheet->disconnectWorksheets(); + } +} diff --git a/tests/data/Reader/XLSX/octo#thorpe.xlsx b/tests/data/Reader/XLSX/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