Skip to content

Commit 2776c45

Browse files
filippotosoProgi1984
authored andcommitted
Word2007 Reader : Fixed reading of Office365 DocX file
1 parent 2c0488c commit 2776c45

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/PhpWord/Shared/XMLReader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function getDomFromZip($zipFile, $xmlFile)
6262

6363
$zip = new ZipArchive();
6464
$zip->open($zipFile);
65-
$content = $zip->getFromName($xmlFile);
65+
$content = $zip->getFromName(ltrim($xmlFile, '/'));
6666
$zip->close();
6767

6868
if ($content === false) {

tests/PhpWordTests/Shared/XMLReaderTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,21 @@ public function testDomFromZip(): void
5858
self::assertFalse($reader->getDomFromZip($archiveFile, 'non_existing_xml_file.xml'));
5959
}
6060

61+
/**
62+
* Office 365 add some slash before the path of XML file
63+
*/
64+
public function testDomFromZipOffice365(): void
65+
{
66+
$archiveFile = __DIR__ . '/../_files/xml/reader.zip';
67+
68+
$reader = new XMLReader();
69+
$reader->getDomFromZip($archiveFile, '/test.xml');
70+
71+
self::assertTrue($reader->elementExists('/element/child'));
72+
73+
self::assertFalse($reader->getDomFromZip($archiveFile, 'non_existing_xml_file.xml'));
74+
}
75+
6176
/**
6277
* Test that read from non existing archive throws exception.
6378
*/

0 commit comments

Comments
 (0)