Skip to content

Word2007 Reader : Fixed reading of Office365 DocX file #2506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changes/1.x/1.2.0.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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