Skip to content

Commit

Permalink
Avoid corruption when having selfclosing <w:sdtContent/> in the doc
Browse files Browse the repository at this point in the history
  • Loading branch information
edi9999 committed Sep 21, 2020
1 parent a5360b0 commit e50b217
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
### 3.19.4

Avoid corruption when having self closing `<w:sdtContent/>` in the document.

### 3.19.3

Throw an error when calling render on an invalid template.
Expand Down
3 changes: 3 additions & 0 deletions es6/join-uncorrupt.js
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions es6/tests/integration.js
Expand Up @@ -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({
Expand Down
Binary file added examples/expected-self-closing-w-sdtcontent.docx
Binary file not shown.
Binary file added examples/self-closing-w-sdtcontent.docx
Binary file not shown.

0 comments on commit e50b217

Please sign in to comment.