guigrpa / docx-templates

Template-based docx report creation
MIT License
882 stars 145 forks source link

Proposed Fix for Issue #340, don't allow nested IFs on same w:p or w:… #353

Closed dseiler closed 5 months ago

dseiler commented 6 months ago

Proposed Fix for Issue #340, don't allow nested IFs on same w:p or w:r tag. Added some code to the processTemplate.ts file to throw an exception in the processForIf function if an IF statement is nested within another IF on the same w:p or w:r tag. I had to add two map variables to the context for keeping track the corrent w:p or w:r node. I also added three tests. Those tests run into an infinite loop if my fix is not applied. All the other tests run correctly. Please verify and if ok add to the next version of docx-templates. Thanks!

dseiler commented 6 months ago

Thanks for your feedback. Highly appreciated. I updated my pull request with your comments. I also added a new "emergency exit" to the main while loop in case something runs out of control. I.e. if we run into an endless loop we should throw and exception. Let me know if this makes sense. Thanks!

jjhbw commented 5 months ago

Reverted the yarn.lock change and squash-merged this MR offline, making sure to retain your authorship info. See f069eb22469a296db555faafbb164fa7b68c7f7f

Thanks for the contribution, and apologies for my late reactions.