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

fix: corrupted docx issue caused by duplicate extensions in ContentType.xml with different casing #400

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ACHP
Copy link

@ACHP ACHP commented Jan 28, 2025

Description

This PR addresses a bug where the ContentType.xml file could be corrupted due to duplicate entries of the same file extension with different casing. For example, if a template specifies an uppercase extension (JPG), but the generated report inserts a lowercase extension (jpg), the ContentType.xml ends up with two entries:

<Default Extension="JPG" ContentType="image/jpeg"/>
<Default Extension="jpg" ContentType="image/jpeg"/>

As a result, the DOCX file becomes invalid.
image

Solution

To fix this issue, we updated the ensureContentType function to be case-insensitive when adding new extensions. This change ensures that only one entry is created for a given extension, regardless of its casing.

Changes
• Updated ensureContentType to treat extensions in a case-insensitive manner.

How to reproduce:

  • Create a docx file with a JPG image in it, (make sure the extension is uppercase)
  • Use it as a templte to insert a jpg (lowercase) image
  • open the docx

@ACHP ACHP changed the title write initial test fix: Avoid dupplicating extension in the ContentType.xml file corrupt the docx Jan 28, 2025
@ACHP ACHP changed the title fix: Avoid dupplicating extension in the ContentType.xml file corrupt the docx fix: corrupted docx issue caused by duplicate extensions in ContentType.xml with different casing Jan 28, 2025
@ACHP ACHP marked this pull request as ready for review January 28, 2025 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant