From 94b74c27a42084e6184047620ee076d65f075145 Mon Sep 17 00:00:00 2001 From: Ebben Feagan Date: Fri, 16 Apr 2021 15:06:37 -0500 Subject: [PATCH 1/3] when adding image to relationship list check that the generated relationship id is actually unique --- src/PhpWord/TemplateProcessor.php | 33 +++++++++++++++++++------------ 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/PhpWord/TemplateProcessor.php b/src/PhpWord/TemplateProcessor.php index 649fde40c8..a591ad5ae3 100644 --- a/src/PhpWord/TemplateProcessor.php +++ b/src/PhpWord/TemplateProcessor.php @@ -1,4 +1,5 @@ getMainPartName() => &$this->tempDocumentMainPart, - ); + $this->getMainPartName() => &$this->tempDocumentMainPart, + ); foreach (array_keys($this->tempDocumentHeaders) as $headerIndex) { $searchParts[$this->getHeaderName($headerIndex)] = &$this->tempDocumentHeaders[$headerIndex]; } @@ -661,7 +662,7 @@ public function setImageValue($search, $replace, $limit = self::MAXIMUM_REPLACEM if (preg_match('/(<[^<]+>)([^<]*)(' . preg_quote($varNameWithArgsFixed) . ')([^>]*)(<[^>]+>)/Uu', $partContent, $matches)) { $wholeTag = $matches[0]; array_shift($matches); - list($openTag, $prefix, , $postfix, $closeTag) = $matches; + list($openTag, $prefix,, $postfix, $closeTag) = $matches; $replaceXml = $openTag . $prefix . $closeTag . $xmlImage . $openTag . $postfix . $closeTag; // replace on each iteration, because in one tag we can have 2+ inline variables => before proceed next variable we need to change $partContent $partContent = $this->setValueForPart($wholeTag, $replaceXml, $partContent, $limit); @@ -747,8 +748,10 @@ 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('##', $tmpXmlRow) && - !preg_match('##', $tmpXmlRow)) { + if ( + !preg_match('##', $tmpXmlRow) && + !preg_match('##', $tmpXmlRow) + ) { break; } // This row was a spanned row, update $rowEnd and search for the next row. @@ -1067,7 +1070,11 @@ protected function getRelationsName($documentPartName) protected function getNextRelationsIndex($documentPartName) { if (isset($this->tempDocumentRelations[$documentPartName])) { - return substr_count($this->tempDocumentRelations[$documentPartName], 'tempDocumentRelations[$documentPartName], 'tempDocumentRelations[$documentPartName], 'Id="rId' . $candidate . '"') !== false) { + $candidate++; + } + return $candidate; } return 1; From 524c08bafb87f7652005084c3d3b9f8b423adda2 Mon Sep 17 00:00:00 2001 From: Ebben Feagan Date: Fri, 16 Apr 2021 15:19:55 -0500 Subject: [PATCH 2/3] running composer fix --- src/PhpWord/TemplateProcessor.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/PhpWord/TemplateProcessor.php b/src/PhpWord/TemplateProcessor.php index a591ad5ae3..582c350987 100644 --- a/src/PhpWord/TemplateProcessor.php +++ b/src/PhpWord/TemplateProcessor.php @@ -18,14 +18,14 @@ namespace PhpOffice\PhpWord; -use PhpOffice\PhpWord\Shared\ZipArchive; -use PhpOffice\PhpWord\Shared\XMLWriter; -use PhpOffice\PhpWord\Shared\Text; -use PhpOffice\PhpWord\Exception\Exception; -use PhpOffice\PhpWord\Exception\CreateTemporaryFileException; -use PhpOffice\PhpWord\Exception\CopyFileException; -use PhpOffice\PhpWord\Escaper\Xml; use PhpOffice\PhpWord\Escaper\RegExp; +use PhpOffice\PhpWord\Escaper\Xml; +use PhpOffice\PhpWord\Exception\CopyFileException; +use PhpOffice\PhpWord\Exception\CreateTemporaryFileException; +use PhpOffice\PhpWord\Exception\Exception; +use PhpOffice\PhpWord\Shared\Text; +use PhpOffice\PhpWord\Shared\XMLWriter; +use PhpOffice\PhpWord\Shared\ZipArchive; class TemplateProcessor { @@ -662,7 +662,7 @@ public function setImageValue($search, $replace, $limit = self::MAXIMUM_REPLACEM if (preg_match('/(<[^<]+>)([^<]*)(' . preg_quote($varNameWithArgsFixed) . ')([^>]*)(<[^>]+>)/Uu', $partContent, $matches)) { $wholeTag = $matches[0]; array_shift($matches); - list($openTag, $prefix,, $postfix, $closeTag) = $matches; + list($openTag, $prefix, , $postfix, $closeTag) = $matches; $replaceXml = $openTag . $prefix . $closeTag . $xmlImage . $openTag . $postfix . $closeTag; // replace on each iteration, because in one tag we can have 2+ inline variables => before proceed next variable we need to change $partContent $partContent = $this->setValueForPart($wholeTag, $replaceXml, $partContent, $limit); @@ -1074,6 +1074,7 @@ protected function getNextRelationsIndex($documentPartName) while (strpos($this->tempDocumentRelations[$documentPartName], 'Id="rId' . $candidate . '"') !== false) { $candidate++; } + return $candidate; } From 7fd04895676ed5b46379d6ec697aebce40021356 Mon Sep 17 00:00:00 2001 From: troosan Date: Fri, 16 Apr 2021 23:38:14 +0200 Subject: [PATCH 3/3] fix checkstyle issues --- src/PhpWord/TemplateProcessor.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/PhpWord/TemplateProcessor.php b/src/PhpWord/TemplateProcessor.php index 582c350987..3f7770d3d7 100644 --- a/src/PhpWord/TemplateProcessor.php +++ b/src/PhpWord/TemplateProcessor.php @@ -748,8 +748,7 @@ 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('##', $tmpXmlRow) && + if (!preg_match('##', $tmpXmlRow) && !preg_match('##', $tmpXmlRow) ) { break;