Merge pull request #2063 from tpv-ebben/develop

when adding image to relationship first check that the generated RID is actually unique
This commit is contained in:
troosan 2021-05-29 17:58:25 +02:00 committed by GitHub
commit d905e764e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 4 deletions

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* This file is part of PHPWord - A pure PHP library for reading and writing * This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents. * word processing documents.
@ -620,8 +621,8 @@ class TemplateProcessor
// collect document parts // collect document parts
$searchParts = array( $searchParts = array(
$this->getMainPartName() => &$this->tempDocumentMainPart, $this->getMainPartName() => &$this->tempDocumentMainPart,
); );
foreach (array_keys($this->tempDocumentHeaders) as $headerIndex) { foreach (array_keys($this->tempDocumentHeaders) as $headerIndex) {
$searchParts[$this->getHeaderName($headerIndex)] = &$this->tempDocumentHeaders[$headerIndex]; $searchParts[$this->getHeaderName($headerIndex)] = &$this->tempDocumentHeaders[$headerIndex];
} }
@ -748,7 +749,8 @@ class TemplateProcessor
// If tmpXmlRow doesn't contain continue, this row is no longer part of the spanned row. // If tmpXmlRow doesn't contain continue, this row is no longer part of the spanned row.
$tmpXmlRow = $this->getSlice($extraRowStart, $extraRowEnd); $tmpXmlRow = $this->getSlice($extraRowStart, $extraRowEnd);
if (!preg_match('#<w:vMerge/>#', $tmpXmlRow) && if (!preg_match('#<w:vMerge/>#', $tmpXmlRow) &&
!preg_match('#<w:vMerge w:val="continue"\s*/>#', $tmpXmlRow)) { !preg_match('#<w:vMerge w:val="continue"\s*/>#', $tmpXmlRow)
) {
break; break;
} }
// This row was a spanned row, update $rowEnd and search for the next row. // This row was a spanned row, update $rowEnd and search for the next row.
@ -1067,7 +1069,12 @@ class TemplateProcessor
protected function getNextRelationsIndex($documentPartName) protected function getNextRelationsIndex($documentPartName)
{ {
if (isset($this->tempDocumentRelations[$documentPartName])) { if (isset($this->tempDocumentRelations[$documentPartName])) {
return substr_count($this->tempDocumentRelations[$documentPartName], '<Relationship'); $candidate = substr_count($this->tempDocumentRelations[$documentPartName], '<Relationship');
while (strpos($this->tempDocumentRelations[$documentPartName], 'Id="rId' . $candidate . '"') !== false) {
$candidate++;
}
return $candidate;
} }
return 1; return 1;