From eb050201d56d68fcb588fdf73b43ebd7748e5394 Mon Sep 17 00:00:00 2001 From: Viktor Date: Sat, 1 Jan 2022 14:28:57 +0300 Subject: [PATCH] fix: fix image tags --- .phpunit.result.cache | 2 +- src/DocxDocument.php | 3 ++- tests/templates/image.docx | Bin 1446077 -> 1446079 bytes 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.phpunit.result.cache b/.phpunit.result.cache index 4e8f32e..a71db12 100644 --- a/.phpunit.result.cache +++ b/.phpunit.result.cache @@ -1 +1 @@ -{"version":1,"defects":{"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testTable":3,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testImages":4},"times":{"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testTable":0.0050000000000000001,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testXmlToString":0.0080000000000000002,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testGetDocx":0.012999999999999999,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testGetXml":0.002,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testPatchXml":0.0030000000000000001,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testRenderXml":0.031,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testRender":0.012,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testLineBreak":0.012999999999999999,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testCyrillic":0.0089999999999999993,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testForLoop":0.025000000000000001,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testImages":2.1080000000000001}} \ No newline at end of file +{"version":1,"defects":{"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testTable":3,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testImages":4},"times":{"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testTable":0.010999999999999999,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testXmlToString":0.17499999999999999,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testGetDocx":0.0040000000000000001,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testGetXml":0.002,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testPatchXml":0.0030000000000000001,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testRenderXml":0.23100000000000001,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testRender":0.012999999999999999,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testLineBreak":0.0060000000000000001,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testCyrillic":0.002,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testForLoop":0.042000000000000003,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testImages":2.468}} \ No newline at end of file diff --git a/src/DocxDocument.php b/src/DocxDocument.php index 04a32e5..2bcda78 100644 --- a/src/DocxDocument.php +++ b/src/DocxDocument.php @@ -492,9 +492,10 @@ public function setImageValue($search, $replace): void $matches = array(); if (preg_match('/(<[^<]+>)([^<]*)(' . preg_quote($varNameWithArgsFixed) . ')([^>]*)(<[^>]+>)/Uu', $partContent, $matches)) { $wholeTag = $matches[0]; + $before = str_replace($varNameWithArgsFixed, '', $wholeTag); array_shift($matches); list($openTag, $prefix, , $postfix, $closeTag) = $matches; - $replaceXml = $openTag . $prefix . $closeTag . $xmlImage . $openTag . $postfix . $closeTag; + $replaceXml = $before . $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); } diff --git a/tests/templates/image.doc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