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:
parent
290c18e4db
commit
d5825a6682
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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.
Loading…
Reference in New Issue