diff --git a/docs/changes/1.x/1.2.0.md b/docs/changes/1.x/1.2.0.md index d65f27490b..1b8e1daea9 100644 --- a/docs/changes/1.x/1.2.0.md +++ b/docs/changes/1.x/1.2.0.md @@ -38,6 +38,7 @@ - Fixed PHP 8.2 deprecated about Allow access to an undefined property by [@DAdq26](https://github.com/DAdq26) in GH-2440 - Template Processor : Fixed choose dimention for Float Value by [@gdevilbat](https://github.com/gdevilbat) in GH-2449 - HTML Parser : Fix image parsing from url without extension by [@JokubasR](https://github.com/JokubasR) in GH-2459 +- Word2007 Reader : Fixed reading of Office365 DocX file by [@filippotoso](https://github.com/filippotoso) & [@lfglopes](https://github.com/lfglopes) in [#2506](https://github.com/PHPOffice/PHPWord/pull/2506) ### Miscellaneous diff --git a/src/PhpWord/Shared/XMLReader.php b/src/PhpWord/Shared/XMLReader.php index c508b3d320..1c95a64426 100644 --- a/src/PhpWord/Shared/XMLReader.php +++ b/src/PhpWord/Shared/XMLReader.php @@ -62,7 +62,7 @@ public function getDomFromZip($zipFile, $xmlFile) $zip = new ZipArchive(); $zip->open($zipFile); - $content = $zip->getFromName($xmlFile); + $content = $zip->getFromName(ltrim($xmlFile, '/')); $zip->close(); if ($content === false) { diff --git a/tests/PhpWordTests/Shared/XMLReaderTest.php b/tests/PhpWordTests/Shared/XMLReaderTest.php index 9ba8e4548b..4cbe92a5e2 100644 --- a/tests/PhpWordTests/Shared/XMLReaderTest.php +++ b/tests/PhpWordTests/Shared/XMLReaderTest.php @@ -58,6 +58,21 @@ public function testDomFromZip(): void self::assertFalse($reader->getDomFromZip($archiveFile, 'non_existing_xml_file.xml')); } + /** + * Office 365 add some slash before the path of XML file. + */ + public function testDomFromZipOffice365(): void + { + $archiveFile = __DIR__ . '/../_files/xml/reader.zip'; + + $reader = new XMLReader(); + $reader->getDomFromZip($archiveFile, '/test.xml'); + + self::assertTrue($reader->elementExists('/element/child')); + + self::assertFalse($reader->getDomFromZip($archiveFile, 'non_existing_xml_file.xml')); + } + /** * Test that read from non existing archive throws exception. */