Skip to content
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

Bug Report: Duplicate Commands in Docx-Templates #374

Open
Amerlander opened this issue Jun 29, 2024 · 1 comment
Open

Bug Report: Duplicate Commands in Docx-Templates #374

Amerlander opened this issue Jun 29, 2024 · 1 comment
Labels

Comments

@Amerlander
Copy link

Description

When commands are included inside a text field, docx-templates processes the command twice. This results in the command appearing twice in the command list and being executed twice. Although the final output appears correct, this redundancy leads to unnecessary parsing, thereby increasing resource usage.

Steps to Reproduce

  1. Create a DOCX file with a docx-templates-command inside a text-field
  2. Use the listCommands function to parse the template.
  3. Observe the command list output.

Sample

In the provided sample, the first two commands ("artist project ID" and "Bezeichnung") are correctly listed once. However, the third command ("Titelbild"), despite being present only once in the document, is returned twice by listCommands.

Code

import { createReport, listCommands } from 'https://unpkg.com/docx-templates/lib/browser.js';

async function prepareFile() {
    const template = await readFileIntoArrayBuffer(file);
    const cmdDelimiter = ['{#', '#}'];
    const templateMeta = {};
    templateMeta.commands = await listCommands(template, cmdDelimiter);
    console.log(templateMeta);
}

Docx-File

Test (3).docx

Docx-Screenshot

image

Output

image

Expected Behavior

Each command should appear only once in the command list, reflecting its single occurrence in the document.

Actual Behavior

Commands within text fields are listed and executed twice, resulting in duplicated entries in the command list.

Environment

Library Version: https://unpkg.com/docx-templates/lib/browser.js
Browser: Opera One (Version: 111.0.5168.25)
OS: Windows 11

@jjhbw jjhbw added the triage label Jul 4, 2024
@jjhbw
Copy link
Collaborator

jjhbw commented Jul 4, 2024

@Amerlander Thanks for your detailed report. I'll try to reproduce this when I have time. On the face of it, I expect that this happens because of how Word structures text box-related data in the underlying XML.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants