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

Theme File Missing But Referenced in Spreadsheet #3772

Merged
merged 3 commits into from
Oct 26, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
- Break Some Circular References. [PR #3716](https://github.com/PHPOffice/PhpSpreadsheet/pull/3716) [PR #3707](https://github.com/PHPOffice/PhpSpreadsheet/pull/3707)
- Missing Font Index in Some Xls. [PR #3734](https://github.com/PHPOffice/PhpSpreadsheet/pull/3734)
- Load Tables even with READ_DATA_ONLY. [PR #3726](https://github.com/PHPOffice/PhpSpreadsheet/pull/3726)
- Theme File Missing but Referenced in Spreadsheet. [Issue #3770](https://github.com/PHPOffice/PhpSpreadsheet/issues/3770) [PR #3772](https://github.com/PHPOffice/PhpSpreadsheet/pull/3772)

## 1.29.0 - 2023-06-15

Expand Down
3 changes: 3 additions & 0 deletions src/PhpSpreadsheet/Reader/Xlsx.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,9 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet
}
switch ($rel['Type']) {
case "$xmlNamespaceBase/theme":
if (!$this->fileExistsInArchive($zip, "xl/{$relTarget}")) {
break; // issue3770
}
$themeOrderArray = ['lt1', 'dk1', 'lt2', 'dk2'];
$themeOrderAdditional = count($themeOrderArray);

Expand Down
47 changes: 47 additions & 0 deletions tests/PhpSpreadsheetTests/Reader/Xlsx/Issue3770Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;

use PhpOffice\PhpSpreadsheet\Reader\Xlsx;

class Issue3770Test extends \PHPUnit\Framework\TestCase
{
private static string $testbook = 'tests/data/Reader/XLSX/issue.3770.xlsx';

public function testPreliminaries(): void
{
$file = 'zip://';
$file .= self::$testbook;
$file .= '#xl/_rels/workbook.xml.rels';
$data = file_get_contents($file);
// rels file points to non-existent theme file
if ($data === false) {
self::fail('Unable to read file');
} else {
self::assertStringContainsString('Target="theme/theme1.xml"', $data);
self::assertStringContainsString('Target="worksheets/sheet1.xml"', $data);
}
$file = 'zip://';
$file .= self::$testbook;
$file .= '#xl/theme/theme1.xml';
$data = @file_get_contents($file);
self::assertFalse($data);
$file = 'zip://';
$file .= self::$testbook;
$file .= '#xl/worksheets/sheet1.xml';
$data = file_get_contents($file);
self::assertNotFalse($data);
}

public function testLoadable(): void
{
$reader = new Xlsx();
$spreadsheet = $reader->load(self::$testbook);
$sheet = $spreadsheet->getActiveSheet();
// Assert anything to confirm read succeeded
self::assertSame('Универсальный передаточный документ', $sheet->getCell('A1')->getValue());
$spreadsheet->disconnectWorksheets();
}
}
Binary file added tests/data/Reader/XLSX/issue.3770.xlsx
Binary file not shown.