https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33350

--- Comment #6 from Adolfo Rodríguez Taboada <[email protected]> ---
Created attachment 211527
  -->
https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=211527&action=edit
Bug 33350: Fix repeat_enclosing_tags processing multiple identical blocks

The repeat_enclosing_tags code path in GetPreparedLetter used a greedy
regex m!<$tag>(.*)</$tag>!s to locate the block to expand. When a notice
template contains more than one block with the same tag (e.g. a bilingual
ODUE notice with two <item> blocks, one per language), the greedy .* would
consume everything from the first opening tag to the very last closing tag,
merging all blocks into one and losing the text between them.

Fix: replace the single greedy match with a non-greedy while loop that
processes each <tag>...</tag> pair independently. A first pass collects one
expansion per block into @replacements, then a second substitution replaces
each pair in order with its corresponding expansion.

A unit test is added to t/db_dependent/Letters.t verifying that two
<item> blocks in the same template are each expanded independently with
all items, using pre-resolved hashref values to avoid DB lookups.

Steps to follow:
1. Have a notice template (e.g. ODUE email) that contains two or more
   <item>...</item> blocks, such as a bilingual template with one block per
   language.
2. Trigger an overdue notice for a patron with at least one overdue item
   (Tools -> Overdue notices, or overdue_notices.pl).
3. Check the generated notice: only the first <item> block is expanded with
   the item data; the second block is corrupted or its surrounding text is
   swallowed.
4. Apply this patch and restart services. If running under Plack,
   restarting Plack is required for the change to take effect.
5. Trigger the overdue notice again.
6. Verify both <item> blocks are now expanded independently with all
   overdue items listed under each block.
7. Verify that a template with a single <item> block still works correctly.

Signed-off-by: Adolfo Rodríguez <[email protected]>

-- 
You are receiving this mail because:
You are watching all bug changes.
_______________________________________________
Koha-bugs mailing list -- [email protected]
To unsubscribe send an email to [email protected]
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/

Reply via email to