Skip to content

Commit 11a7aaa

Browse files
authored
Merge pull request #2506 from PHPOffice/pr2463
Word2007 Reader : Fixed reading of Office365 DocX file
2 parents 2c0488c + 4139111 commit 11a7aaa

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

docs/changes/1.x/1.2.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
- Fixed PHP 8.2 deprecated about Allow access to an undefined property by [@DAdq26](https://github.com/DAdq26) in GH-2440
3939
- Template Processor : Fixed choose dimention for Float Value by [@gdevilbat](https://github.com/gdevilbat) in GH-2449
4040
- HTML Parser : Fix image parsing from url without extension by [@JokubasR](https://github.com/JokubasR) in GH-2459
41+
- 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)
4142

4243
### Miscellaneous
4344

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)