You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, im experiencing a bug running docx-templates on two "identical" documents. I'm putting the identical into quotes because even so content is identical, i also unzipped the docx-files and looked into the xml representation of both, where you find the usual word xml construct slashing the text into smaller and smaller xml-nodes, the longer you work on a document ;)
But still, opening them in Word, both files contain identical text:
The payment we refer to is in regard to our {{IF period==Written}}written{{END-IF}}{{IF period==Person}}oral{{END-IF}}{{IF period==Telephone}}oral{{END-IF}} agreement.
But, for whatever reason, the result of this files are different and might duplicate the first and/or 2nd if, depending on the vaule of 'period' (see below).
Reproducable example
I've simpliefied the Template and our service into the small documents and the following script, still able to reproduce the error.
For creating the report, i'm using a custon errorHandler with the idea of replacing missing data in a way, that for missing INS we just use their variablename, missing loops are an emty list and missing booleans are simply true.
But this is unrelated to the issue, as shown in the four examples below.
import{createReport}from"docx-templates";importfsfrom"fs";letbuffer,template;asyncfunctionreportWithErrorHandler(template){returnawaitcreateReport({
template,data: {},cmdDelimiter: ["{{","}}"],failFast: false,errorHandler: (err,command_code)=>{console.log("Error: "+err.message+" in command: "+command_code)// handling missing data,// replacing INS with [variable_name], for booleans this is accepted as true// and missing loops are empty arraysif(err.message.startsWith("ReferenceError")){return"["+command_code.replace("$","")+"]";}if(err.message.startsWith("Invalid FOR command (can only iterate over Array):")){return[];}throwerr;},});}console.log("Running Debt simplified_bugged.docx");template=fs.readFileSync("Debt simplified_bugged.docx");buffer=awaitreportWithErrorHandler(template);fs.writeFileSync("report_bugged.docx",buffer);console.log("Running Debt simplified_working.docx");template=fs.readFileSync("Debt simplified_working.docx");buffer=awaitreportWithErrorHandler(template);fs.writeFileSync("report_working.docx",buffer);
I'm using docx-templates in version 4.11.3 on Node.js v18.17.1. Also tested with docx-templates in v4.11.1
Result based on input-data
without data
Running the script without data generates two files, one with the expected outcome and one with weird duplication:
Result from the "working" file, as expected:
The payment we refer to is in regard to our writtenoraloral agreement.
Result from the bugged-docx:
The payment we refer to is in regard to our writtenwrittenoraloraloral agreement.
"period" : "Written"
If we provide the following data (and therefore avoiding the error handler): json data: { "period" : "Written" }
Everythign is fine, outcome for both files is:
The payment we refer to is in regard to our written agreement.
"period" : "Person"
However if we provide the period "Person" json data: { "period" : "Person" }
We get two different results, one as expected (from the _working-File):
The payment we refer to is in regard to our oral agreement.
but the bugged-one looks like this:
The payment we refer to is in regard to our writtenoral agreement.
"period" : "Telephone"
If we provide the third option: "Telephone" json data: { "period" : "Telephone" }
Working:
The payment we refer to is in regard to our oral agreement.
As (kinda) expected one is working flawless, the bugged one now looks like this:
The payment we refer to is in regard to our oraloral agreement.
Summary
While we do have a working docx-File, i think this example might point to an underlying bug, that would be wounderfull if we can get rid of. Also im having a hard way reasoning to people using the docx-templates with two identical documents does not provide identical results :D
I hope i've included averything to reproduce and hopefully get rid of this bug.
Thank you for your work on this awesome package,
Cheers
The text was updated successfully, but these errors were encountered:
Hi, im experiencing a bug running docx-templates on two "identical" documents. I'm putting the identical into quotes because even so content is identical, i also unzipped the docx-files and looked into the xml representation of both, where you find the usual word xml construct slashing the text into smaller and smaller xml-nodes, the longer you work on a document ;)
But still, opening them in Word, both files contain identical text:
But, for whatever reason, the result of this files are different and might duplicate the first and/or 2nd if, depending on the vaule of 'period' (see below).
Reproducable example
I've simpliefied the Template and our service into the small documents and the following script, still able to reproduce the error.
For creating the report, i'm using a custon errorHandler with the idea of replacing missing data in a way, that for missing INS we just use their variablename, missing loops are an emty list and missing booleans are simply true.
But this is unrelated to the issue, as shown in the four examples below.
here are two identical documents:
Debt simplified_working.docx
Debt simplified_bugged.docx
I'm using docx-templates in version 4.11.3 on Node.js v18.17.1. Also tested with docx-templates in v4.11.1
Result based on input-data
without data
Running the script without data generates two files, one with the expected outcome and one with weird duplication:
Result from the "working" file, as expected:
Result from the bugged-docx:
"period" : "Written"
If we provide the following data (and therefore avoiding the error handler):
json data: { "period" : "Written" }
Everythign is fine, outcome for both files is:
"period" : "Person"
However if we provide the period "Person"
json data: { "period" : "Person" }
We get two different results, one as expected (from the _working-File):
but the bugged-one looks like this:
"period" : "Telephone"
If we provide the third option: "Telephone"
json data: { "period" : "Telephone" }
Working:
As (kinda) expected one is working flawless, the bugged one now looks like this:
Summary
While we do have a working docx-File, i think this example might point to an underlying bug, that would be wounderfull if we can get rid of. Also im having a hard way reasoning to people using the docx-templates with two identical documents does not provide identical results :D
I hope i've included averything to reproduce and hopefully get rid of this bug.
Thank you for your work on this awesome package,
Cheers
The text was updated successfully, but these errors were encountered: