-
Notifications
You must be signed in to change notification settings - Fork 372
Closed
Description
Hi,
The things I know are:
- My site crashes because of this loop in the docxtemplater.
- The contentLength is about 140'000 and cursor is 0 in the start.
- It doesn't execute totalMatches.push because it crashes before.
docxtemplater code:
while (cursor < contentLength) {
cursor = content.indexOf("<", cursor);
if (cursor === -1) {
break;
}
var offset = cursor;
cursor = content.indexOf(">", cursor);
var tagText = content.slice(offset, cursor + 1);
var _getTag = getTag(tagText),
tag = _getTag.tag,
position = _getTag.position;
var text = allMatches[tag];
if (text == null) {
continue;
}
totalMatches.push({
type: "tag",
position: position,
text: text,
offset: offset,
value: tagText,
tag: tag
});
}
my script:
function doIt() {
function loadFile(url, callback) {
JSZipUtils.getBinaryContent(url, callback);
}
loadFile('../tag-example.docx', function(error, content) {
if (error) {
throw error;
}
var zip = new JSZip();
zip.file('word/document.xml', content);
var doc = new Docxtemplater().loadZip(zip);
doc.setData({
first_name: 'John',
last_name: 'Doe',
phone: '0652455478',
description: 'New Website'
});
try {
// render the document (replace all occurences of {first_name} by John, {last_name} by Doe, ...)
doc.render();
console.log('asdf');
} catch (error) {
var e = {
message: error.message,
name: error.name,
stack: error.stack,
properties: error.properties
};
console.log(JSON.stringify({ error: e }));
// The error thrown here contains additional information when logged with JSON.stringify (it contains a property object).
throw error;
}
console.log('rendered');
var out = doc.getZip().generate({
type: 'blob',
mimeType:
'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
}); //Output the document using Data-URI
saveAs(out, 'output.docx');
});
}