Skip to content

Commit

Permalink
Merge pull request #2506 from PHPOffice/pr2463
Browse files Browse the repository at this point in the history
Word2007 Reader : Fixed reading of Office365 DocX file
  • Loading branch information
Progi1984 committed Nov 22, 2023
2 parents 2c0488c + 4139111 commit 11a7aaa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/changes/1.x/1.2.0.md
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/PhpWord/Shared/XMLReader.php
Expand Up @@ -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) {
Expand Down
15 changes: 15 additions & 0 deletions tests/PhpWordTests/Shared/XMLReaderTest.php
Expand Up @@ -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.
*/
Expand Down

0 comments on commit 11a7aaa

Please sign in to comment.