-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shift + Enter between two IF conditions #340
Comments
Similar in my case, was fighting endless loops aswell. I think in the end I've monkeypatched an loop-counter in there, to at least stop the loop and have a proper error handling. Let me check tomorrow on my workaround, mby it helps you. |
Possibly related to #154?
|
Hi @KingofGnome, |
@matcobat @KingofGnome I was also able to reproduce this issue. Looks like this is a big problem for us now because we cannot guarantee that our users are not creating such a corrupt template. |
I don't know of an immediate solution to this. Because the result of this bug is an infinite loop, the most likely culprit is the docx-templates/src/processTemplate.ts Line 170 in ac067bd
This function is very much 'core' to the application and hence challenging to change without breaking other behaviour. If you want to give this a go, we have a pretty solid suite of snapshot tests to use as guardrails. I would start by creating a snapshot test for your template that triggers the infinite loop (using a Jest timeout or by instrumenting |
Thanks for the hint. I did a first debugging and found that the while(true) loop at line 183 in the processTemplate.ts file is never exiting. There is only one "break" statement in this loop at line 217 which could exit this loop. This statement is never true so we have an infinite loop. processTemplate.ts , line 215-221 |
Mby try to unzip two similar docx files and compare both xml's. |
I did some in depth debugging on this issue and I found that two nested IF commands within the same paragraph (shift enter does not create a new paragraph) is causing the walkTemplate function on the processTemplate.ts to jump to the wrong node and therefore enter in an endless loop. |
Pull requests are welcome and very much appreciated, especially if they come with tests! |
Hi,
First, I would like to say that I really love docx-templates !
I recently found a bug, that makes the "createReport" method looping in an infinite way (so, my application do not answer anymore :().
I am actually using the NodeJS version.
Here is an example of a template that cause the bug.
If I replace the "Shift Enter" by a simple "Enter" after the first IF, it is working fine.
On my application, since I let users to create their own templates, I can not check all the templates. Since this is completely crashing my app, it is very annoying.
if it could work, of throw an error, it would be fantastic !
Thanks !
The text was updated successfully, but these errors were encountered: