Skip to content

Commit 55a5913

Browse files
authored
fix: preserve empty comment initials (#506)
1 parent 4ffed02 commit 55a5913

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@stll/folio-core": patch
3+
---
4+
5+
Preserve explicitly empty initials on comments.

packages/core/src/docx/serializer/commentSerializer.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ describe("serializeComments", () => {
6060
expect(xml).toContain('<w:comment w:id="1" w:author=""');
6161
});
6262

63+
test("preserves an explicitly empty initials attribute", () => {
64+
const comment = { ...makeComment(1), initials: "" };
65+
const xml = serializeComments([comment]);
66+
67+
expect(xml).toContain('w:initials=""');
68+
expect(parseComments(xml, null, null, new Map(), new Map()).at(0)?.initials).toBe("");
69+
});
70+
6371
test("escapes a paragraph paraId that carries markup instead of a real Word id", () => {
6472
// A malformed/attacker-supplied `paraId` (e.g. relayed through a
6573
// collaboration payload) must not be able to break out of the

packages/core/src/docx/serializer/commentSerializer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function serializeParagraphWithAnnotationRef(
4343

4444
function serializeComment(comment: Comment): string {
4545
const attrs: string[] = [`w:id="${comment.id}"`, `w:author="${escapeXml(comment.author)}"`];
46-
if (comment.initials) {
46+
if (comment.initials !== undefined) {
4747
attrs.push(`w:initials="${escapeXml(comment.initials)}"`);
4848
}
4949
if (comment.date) {

0 commit comments

Comments
 (0)