Not Finding Rels File (#3554)

* Not Finding Rels File

Fix #3553. Read of `\xl\worksheets\_rels\sheet1.xml.rels` fails on the new test worksheet (generated by 3rd party product), but read of `xl\worksheets\_rels\sheet1.xml.rels` (same name without leading slash) succeeds. I'm not sure why (over 400 tests succeed with the slash), so will probably delay this a bit while I do more research.

* Move Fix

Move to more logical place.
This commit is contained in:
oleibman
2023-05-10 18:09:05 -07:00
committed by GitHub
parent 623caa89bc
commit b3112e4b43
3 changed files with 41 additions and 0 deletions
+4
View File
@@ -525,6 +525,10 @@ class Xlsx extends BaseReader
foreach ($rels->Relationship as $relx) {
$rel = self::getAttributes($relx);
$relTarget = (string) $rel['Target'];
// issue 3553
if ($relTarget[0] === '/') {
$relTarget = substr($relTarget, 1);
}
$relType = (string) $rel['Type'];
$mainNS = self::REL_TO_MAIN[$relType] ?? Namespaces::MAIN;
switch ($relType) {
@@ -0,0 +1,37 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
class Issue3553Test extends \PHPUnit\Framework\TestCase
{
/**
* @var string
*/
private static $testbook = 'tests/data/Reader/XLSX/issue.3553.xlsx';
public function testPreliminaries(): void
{
$file = 'zip://';
$file .= self::$testbook;
$file .= '#_rels/.rels';
$data = file_get_contents($file);
// confirm that file contains expected namespaced xml tag
if ($data === false) {
self::fail('Unable to read file');
} else {
self::assertStringContainsString('<Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="/xl/workbook.xml" Id="rId2" />', $data, 'Unexpected leading slash in Target attribute');
}
}
public function testIssue3553(): void
{
$reader = new Xlsx();
$spreadsheet = $reader->load(self::$testbook);
$sheet = $spreadsheet->getActiveSheet();
self::assertSame('https://microsoft.com/', $sheet->getCell('B2')->getHyperlink()->getUrl());
$spreadsheet->disconnectWorksheets();
}
}
Binary file not shown.