-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Open
Labels
Description
Describe the Bug
When you have multiple Blocks in multiple Rows, some of blocks cannot be replaced
Only the last block was replaced.
This because some word file will drop-line after xml tag, and the regular expression engine in different versions cannot find the matched block.
Steps to Reproduce
See the image below, only blocks #6 has been replaced.
- TemplateProcessor
- The template has a table with clone rows. Each row has different dynamic data.
- The blocks name in each row will be
block#1,block#2,...
<?php
...
$this->processor->cloneRow('client', $amount);
for (...) {
$suffix = '#' . ($i + 1);
// block_year.
$this->processor->cloneBlock('block_year' . $suffix);
}Expected Behavior
Replaced all Blocks
Current Behavior
Only blocks in the last row was replaced
Context
Please fill in your environment information:
- PHP Version: 7.3.9
- PHPWord Version: 0.17.0
Fix & Pull Request:
File: TemplateProcessor.php
Line: 740
Change the regexp pattern to:
'/(.*((?s)<w:p\b(?:(?!<w:p\b).)*?\${' . $blockname . '}<\/w:.*?p>))(.*)((?s)<w:p\b(?:(?!<w:p\b).)*?\${\/' . $blockname . '}<\/w:.*?p>)/is',Describe:
- Do not find for xml.
- Start find the
<w:ptag that closest to the blockname. - This
<w:pdoes not contain any other<w:pinside it.
Hope this helps.

