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

Handle absolute path in worksheets Target #1769

Merged
merged 7 commits into from
Apr 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove unnecessary changes. Added test
  • Loading branch information
tiagof committed Apr 19, 2021
commit 559c0761df56827d69ecec634345b39f8d0a324e
4 changes: 1 addition & 3 deletions src/PhpSpreadsheet/Reader/Xlsx.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class Xlsx extends BaseReader
* @var ReferenceHelper
*/
private $referenceHelper;

/**
* Xlsx\Theme instance.
*
Expand Down Expand Up @@ -471,10 +470,9 @@ public function load($pFilename)
}

$xpath = self::getArrayItem($relsWorkbook->xpath("rel:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles']"));
$xpathPath = strpos($xpath['Target'], '/') === 0 ? substr($xpath['Target'], 1) : "$dir/$xpath[Target]";
//~ http://schemas.openxmlformats.org/spreadsheetml/2006/main"
$xmlStyles = simplexml_load_string(
$this->securityScanner->scan($this->getFromZipArchive($zip, $xpathPath)),
$this->securityScanner->scan($this->getFromZipArchive($zip, "$dir/$xpath[Target]")),
'SimpleXMLElement',
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.