Skip to content

Commit 1f70f65

Browse files
authored
Merge pull request #53 from Progi1984/pr28
Remove leading slash when required
2 parents 8303744 + c5d8264 commit 1f70f65

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/Common/XMLReader.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ public function getDomFromZip(string $zipFile, string $xmlFile)
6161
$zip = new \ZipArchive();
6262
$zip->open($zipFile);
6363
$content = $zip->getFromName($xmlFile);
64+
65+
// Files downloaded from Sharepoint are somehow different and fail on the leading slash.
66+
if ($content === false && substr($xmlFile, 0, 1) === '/') {
67+
$content = $zip->getFromName(substr($xmlFile, 1));
68+
}
69+
6470
$zip->close();
6571

6672
if ($content === false) {

tests/Common/Tests/XMLReaderTest.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,24 @@ public function testDomFromZip(): void
5151
$pathResources = PHPOFFICE_COMMON_TESTS_BASE_DIR . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR;
5252

5353
$reader = new XMLReader();
54-
$reader->getDomFromZip($pathResources . 'reader.zip', 'test.xml');
54+
$this->assertInstanceOf(\DOMDocument::class, $reader->getDomFromZip($pathResources . 'reader.zip', 'test.xml'));
5555

5656
$this->assertTrue($reader->elementExists('/element/child'));
5757

5858
$this->assertFalse($reader->getDomFromZip($pathResources . 'reader.zip', 'non_existing_xml_file.xml'));
5959
}
6060

61+
/**
62+
* Test reading XML from zip
63+
*/
64+
public function testDomFromZipWithSharepointPath(): void
65+
{
66+
$pathResources = PHPOFFICE_COMMON_TESTS_BASE_DIR . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR;
67+
68+
$reader = new XMLReader();
69+
$this->assertInstanceOf(\DOMDocument::class, $reader->getDomFromZip($pathResources . 'reader.zip', '/test.xml'));
70+
}
71+
6172
/**
6273
* Test that read from non existing archive throws exception
6374
*/

0 commit comments

Comments
 (0)