Skip to content

Cannot read properties of undefined (reading 'lIndex') when parsing template #680

@mcat95

Description

@mcat95

Environment

  • Version of docxtemplater : 3.31.3
  • Used docxtemplater-modules : None needed
  • Runner : NodeJS

How to reproduce my problem :

My template is the following: template.zip

With the following js file :

const fs = require('fs');
const PizZip = require('pizzip');
const Docxtemplater = require('docxtemplater');

const content = fs
    .readFileSync(__dirname + "/template.zip", "binary");

const zip = new PizZip(content);
const doc = new Docxtemplater(zip, {
  modules: [],
  delimiters: { start: "{{", end: "}}" },
})
console.log('Good');
//Execution does not reach this point, since it fails to parse the document

I would expect it to :

  • not fail. The error message is:
TypeError: Cannot read properties of undefined (reading 'lIndex')
    at /home/marco/Walcu/pedefeprinter/docxtemplater/js/modules/loop.js:331:42
    at Array.some (<anonymous>)
    at LoopModule.postparse (/home/marco/Walcu/pedefeprinter/docxtemplater/js/modules/loop.js:322:15)
    at /home/marco/Walcu/pedefeprinter/docxtemplater/js/parser.js:226:24
    at Array.reduce (<anonymous>)
    at _postparse (/home/marco/Walcu/pedefeprinter/docxtemplater/js/parser.js:225:22)
    at postparse (/home/marco/Walcu/pedefeprinter/docxtemplater/js/parser.js:228:20)
    at /home/marco/Walcu/pedefeprinter/docxtemplater/js/modules/expand-pair-trait.js:268:30
    at Array.reduce (<anonymous>)
    at Object.postparse (/home/marco/Walcu/pedefeprinter/docxtemplater/js/modules/expand-pair-trait.js:248:32)

I noticed that this issue didn't appear in 3.30.0, and bisected the repo to found that the commit which introduced the bug was bccf18b

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions