Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read Spreadsheet with # in Name #2409

Merged
merged 2 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/PhpSpreadsheet/Shared/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
20 changes: 20 additions & 0 deletions tests/PhpSpreadsheetTests/Reader/Xlsx/OctothorpeTest.php
Original file line number Diff line number Diff line change
@@ -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 added tests/data/Reader/XLSX/octo#thorpe.xlsx
Binary file not shown.