diff --git a/src/patcher/content-types-manager.spec.ts b/src/patcher/content-types-manager.spec.ts index 5bcebe8c9d..7e4554cf5b 100644 --- a/src/patcher/content-types-manager.spec.ts +++ b/src/patcher/content-types-manager.spec.ts @@ -47,5 +47,31 @@ describe("content-types-manager", () => { type: "element", }); }); + + it("should not append duplicate content type", () => { + const element = { + type: "element", + name: "xml", + elements: [ + { + type: "element", + name: "Types", + elements: [ + { + type: "element", + name: "Default", + attributes: { + ContentType: "image/png", + Extension: "png", + }, + }, + ], + }, + ], + }; + appendContentType(element, "image/png", "png"); + + expect(element.elements.length).toBe(1); + }); }); }); diff --git a/src/patcher/content-types-manager.ts b/src/patcher/content-types-manager.ts index 8032073bfc..8829c3349b 100644 --- a/src/patcher/content-types-manager.ts +++ b/src/patcher/content-types-manager.ts @@ -4,6 +4,18 @@ import { getFirstLevelElements } from "./util"; export const appendContentType = (element: Element, contentType: string, extension: string): void => { const relationshipElements = getFirstLevelElements(element, "Types"); + + const exist = relationshipElements.some( + (el) => + el.type === "element" && + el.name === "Default" && + el?.attributes?.ContentType === contentType && + el?.attributes?.Extension === extension, + ); + if (exist) { + return; + } + // eslint-disable-next-line functional/immutable-data relationshipElements.push({ attributes: {