diff --git a/CHANGELOG.md b/CHANGELOG.md index 444b11a7..7e980405 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### 3.19.4 + +Avoid corruption when having self closing `` in the document. + ### 3.19.3 Throw an error when calling render on an invalid template. diff --git a/es6/join-uncorrupt.js b/es6/join-uncorrupt.js index 5bc478bc..33ff1f15 100644 --- a/es6/join-uncorrupt.js +++ b/es6/join-uncorrupt.js @@ -30,6 +30,9 @@ function joinUncorrupt(parts, contains) { return full; } if (currentlyCollecting === -1 && startTagRegex.test(part)) { + if (part[part.length - 2] === "/") { + return full; + } currentlyCollecting = i; collecting = part; return full; diff --git a/es6/tests/integration.js b/es6/tests/integration.js index aaa4d932..afb9f7a0 100644 --- a/es6/tests/integration.js +++ b/es6/tests/integration.js @@ -416,6 +416,16 @@ describe("Table", function () { shouldBeSame({ doc, expectedName: "expected-raw-xml.docx" }); }); + it("should not corrupt document with selfclosing w:sdtContent tag", function () { + const doc = createDoc("self-closing-w-sdtcontent.docx"); + doc.setData({}); + doc.render(); + shouldBeSame({ + doc, + expectedName: "expected-self-closing-w-sdtcontent.docx", + }); + }); + it("should not corrupt loop containing section", function () { const doc = createDoc("loop-with-section.docx"); doc.setData({ diff --git a/examples/expected-self-closing-w-sdtcontent.docx b/examples/expected-self-closing-w-sdtcontent.docx new file mode 100644 index 00000000..d0c5e9c8 Binary files /dev/null and b/examples/expected-self-closing-w-sdtcontent.docx differ diff --git a/examples/self-closing-w-sdtcontent.docx b/examples/self-closing-w-sdtcontent.docx new file mode 100644 index 00000000..94a1bfbd Binary files /dev/null and b/examples/self-closing-w-sdtcontent.docx differ