Skip to content

Commit 8551040

Browse files
committed
fix
1 parent ebfec01 commit 8551040

2 files changed

Lines changed: 34 additions & 5 deletions

File tree

lib/files/src/SettingsXml.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ export class SettingsXml extends XmlFileWithContentTypes {
206206
attribute ${QNS.r}id { $attachedTemplate }
207207
} else (),
208208
if (exists($documentProtection)) then element ${QNS.w}documentProtection {
209-
attribute ${QNS.w}edit { $documentProtection('edit')},
209+
if ($documentProtection('edit')) then attribute ${QNS.w}edit { $documentProtection('edit')} else (),
210210
attribute ${QNS.w}enforcement { $documentProtection('enforcement') }
211211
} else (),
212212
if (exists($footnoteProperties)) then (
@@ -281,9 +281,14 @@ export class SettingsXml extends XmlFileWithContentTypes {
281281
"isTrackChangesEnabled": docxml:ct-on-off(./${QNS.w}trackChanges),
282282
"evenAndOddHeaders": docxml:ct-on-off(./${QNS.w}evenAndOddHeaders),
283283
"documentProtection": if (./${QNS.w}documentProtection) then (
284-
map {
285-
"edit": string(./${QNS.w}documentProtection/@${QNS.w}edit),
286-
"enforcement": docxml:st-on-off(./${QNS.w}documentProtection/@${QNS.w}enforcement)
284+
let $edit := string(./${QNS.w}documentProtection/@${QNS.w}edit)
285+
let $enforcement := docxml:st-on-off(./${QNS.w}documentProtection/@${QNS.w}enforcement)
286+
return if ($edit)
287+
then map {
288+
"edit": $edit,
289+
"enforcement": $enforcement
290+
} else map {
291+
"enforcement": $enforcement
287292
}
288293
) else ()
289294
}`,

lib/files/test/SettingsXml.test.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe('SettingsXml', () => {
5757
position: 'beneathText',
5858
});
5959
});
60-
it('documentProtection', async () => {
60+
it('documentProtection with edit property', async () => {
6161
const settings = new SettingsXml('test');
6262
expect(settings.get('documentProtection')).toBe(null);
6363
settings.set('documentProtection', {
@@ -84,4 +84,28 @@ describe('SettingsXml', () => {
8484
docxFromArchive.document.settings.get('documentProtection')
8585
).toEqual(customSettings);
8686
});
87+
it('documentProtection without edit', async () => {
88+
const settings = new SettingsXml('test');
89+
expect(settings.get('documentProtection')).toBe(null);
90+
settings.set('documentProtection', {
91+
enforcement: true,
92+
});
93+
expect(settings.get('documentProtection')).toEqual({
94+
enforcement: true,
95+
});
96+
97+
expect(serialize(await settings.$$$toNode())).toEqual(
98+
`<w:settings xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:documentProtection w:enforcement="true"/></w:settings>`
99+
);
100+
101+
const docx = Docx.fromNothing();
102+
const customSettings: DocumentProtectionProps = {
103+
enforcement: false,
104+
};
105+
docx.document.settings.set('documentProtection', customSettings);
106+
const docxFromArchive = await Docx.fromArchive(await docx.toArchive());
107+
expect(
108+
docxFromArchive.document.settings.get('documentProtection')
109+
).toEqual(customSettings);
110+
});
87111
});

0 commit comments

Comments
 (0)