Skip to content

when adding image to relationship first check that the generated RID is actually unique #2063

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 3 commits into from
May 29, 2021
Merged
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
15 changes: 11 additions & 4 deletions src/PhpWord/TemplateProcessor.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
Expand Down Expand Up @@ -620,8 +621,8 @@ public function setImageValue($search, $replace, $limit = self::MAXIMUM_REPLACEM

// collect document parts
$searchParts = array(
$this->getMainPartName() => &$this->tempDocumentMainPart,
);
$this->getMainPartName() => &$this->tempDocumentMainPart,
);
foreach (array_keys($this->tempDocumentHeaders) as $headerIndex) {
$searchParts[$this->getHeaderName($headerIndex)] = &$this->tempDocumentHeaders[$headerIndex];
}
Expand Down Expand Up @@ -748,7 +749,8 @@ public function cloneRow($search, $numberOfClones)
// If tmpXmlRow doesn't contain continue, this row is no longer part of the spanned row.
$tmpXmlRow = $this->getSlice($extraRowStart, $extraRowEnd);
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;
}
// This row was a spanned row, update $rowEnd and search for the next row.
Expand Down Expand Up @@ -1067,7 +1069,12 @@ protected function getRelationsName($documentPartName)
protected function getNextRelationsIndex($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;
Expand Down