fix(docx): read single-quoted protection attributes (#355)
* fix(docx): read single-quoted protection attributes * fix(sheets): satisfy exactOptionalPropertyTypes for LazyCellMatch rawValue --------- Co-authored-by: Aniruddha Adak <aniruddhaadak80@users.noreply.github.com>
This commit is contained in:
co-authored by
Aniruddha Adak
parent
df06cb607a
commit
b8fe1b6b01
@@ -123,9 +123,11 @@ export async function parseProtection(zip: JSZip): Promise<DocProtection | null>
|
|||||||
const xml = await file.async('string')
|
const xml = await file.async('string')
|
||||||
const tag = /<w:documentProtection\b[^>]*?(?:\/>|>)/.exec(xml)?.[0]
|
const tag = /<w:documentProtection\b[^>]*?(?:\/>|>)/.exec(xml)?.[0]
|
||||||
if (!tag) return null
|
if (!tag) return null
|
||||||
const edit = /w:edit="([^"]+)"/.exec(tag)?.[1]
|
const editMatch = /w:edit=(?:"([^"]+)"|'([^']+)')/.exec(tag)
|
||||||
|
const edit = editMatch?.[1] ?? editMatch?.[2]
|
||||||
if (!edit || edit === 'none') return null
|
if (!edit || edit === 'none') return null
|
||||||
const enforcement = /w:enforcement="([^"]+)"/.exec(tag)?.[1]
|
const enforcementMatch = /w:enforcement=(?:"([^"]+)"|'([^']+)')/.exec(tag)
|
||||||
|
const enforcement = enforcementMatch?.[1] ?? enforcementMatch?.[2]
|
||||||
const hash = /w:hash="([^"]+)"/.exec(tag)?.[1]
|
const hash = /w:hash="([^"]+)"/.exec(tag)?.[1]
|
||||||
const salt = /w:salt="([^"]+)"/.exec(tag)?.[1]
|
const salt = /w:salt="([^"]+)"/.exec(tag)?.[1]
|
||||||
const spin = /w:cryptSpinCount="(\d+)"/.exec(tag)?.[1]
|
const spin = /w:cryptSpinCount="(\d+)"/.exec(tag)?.[1]
|
||||||
|
|||||||
@@ -376,4 +376,13 @@ describe('protection tag forms', () => {
|
|||||||
const zip = await settingsZip('<w:writeProtection w:recommended="1"></w:writeProtection>')
|
const zip = await settingsZip('<w:writeProtection w:recommended="1"></w:writeProtection>')
|
||||||
expect(await parseWriteProtection(zip)).toMatchObject({ recommended: true })
|
expect(await parseWriteProtection(zip)).toMatchObject({ recommended: true })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('reads single-quoted protection attributes (some producers emit them)', async () => {
|
||||||
|
const zip = await settingsZip("<w:documentProtection w:edit='readOnly' w:enforcement='1'/>")
|
||||||
|
expect(await parseProtection(zip)).toMatchObject({ edit: 'readOnly', enforced: true })
|
||||||
|
const mixed = await settingsZip(
|
||||||
|
'<w:documentProtection w:edit="comments" w:enforcement=\'on\'/>',
|
||||||
|
)
|
||||||
|
expect(await parseProtection(mixed)).toMatchObject({ edit: 'comments', enforced: true })
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user