Skip to content

Commit

Permalink
Merge pull request #1769 from tiagof/issue-907-absolute-path-in-Target
Browse files Browse the repository at this point in the history
Handle absolute path in worksheets Target
  • Loading branch information
oleibman authored Apr 19, 2021
2 parents caf11fe + 107f707 commit 62f5135
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).

### Fixed

- Fixed issue with absolute path in worksheets' Target. [PR #1769](https://github.com/PHPOffice/PhpSpreadsheet/pull/1769)
- Fix for Xls Reader when SST has a bad length [#1592](https://github.com/PHPOffice/PhpSpreadsheet/issues/1592)
- Resolve Xlsx loader issue whe hyperlinks don't have a destination
- Resolve issues when printer settings resources IDs clash with drawing IDs
Expand Down
3 changes: 2 additions & 1 deletion src/PhpSpreadsheet/Reader/Xlsx.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,12 @@ public function listWorksheetInfo($pFilename)
];

$fileWorksheet = $worksheets[(string) self::getArrayItem($eleSheet->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships'), 'id')];
$fileWorksheetPath = strpos($fileWorksheet, '/') === 0 ? substr($fileWorksheet, 1) : "$dir/$fileWorksheet";

$xml = new XMLReader();
$xml->xml(
$this->securityScanner->scanFile(
'zip://' . File::realpath($pFilename) . '#' . "$dir/$fileWorksheet"
'zip://' . File::realpath($pFilename) . '#' . $fileWorksheetPath
),
null,
Settings::getLibXmlLoaderOptions()
Expand Down
19 changes: 19 additions & 0 deletions tests/PhpSpreadsheetTests/Reader/Xlsx/AbsolutePathTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;

use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
use PHPUnit\Framework\TestCase;

class AbsolutePathTest extends TestCase
{
public static function testPr1869(): void
{
$xlsxFile = 'tests/data/Reader/XLSX/pr1769e.xlsx';
$reader = new Xlsx();
$result = $reader->listWorksheetInfo($xlsxFile);

self::assertIsArray($result);
self::assertEquals(3, $result[0]['totalRows']);
}
}
Binary file added tests/data/Reader/XLSX/pr1769e.xlsx
Binary file not shown.

0 comments on commit 62f5135

Please sign in to comment.