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.
This commit is contained in:
oleibman 2021-11-30 07:39:50 -08:00 committed by GitHub
parent 290c18e4db
commit d5825a6682
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 2 deletions

View File

@ -56,8 +56,8 @@ class File
// 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();

View File

@ -0,0 +1,20 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PHPUnit\Framework\TestCase;
class OctothorpeTest extends TestCase
{
public function testOctothorpeInName(): void
{
// Permit # in file name.
$filename = 'tests/data/Reader/XLSX/octo#thorpe.xlsx';
$reader = IOFactory::createReader('Xlsx');
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getActiveSheet();
self::assertSame('xyz', $sheet->getCell('A1')->getValue());
$spreadsheet->disconnectWorksheets();
}
}

Binary file not shown.