mirror of
https://github.com/foliojs/pdfkit.git
synced 2026-02-01 16:56:57 +00:00
Guard against adding children to ended structure elements.
This commit is contained in:
parent
9c0aaec172
commit
057215fc8f
@ -48,6 +48,10 @@ class PDFStructureElement {
|
||||
}
|
||||
|
||||
add(child) {
|
||||
if (this._ended) {
|
||||
throw new Error(`Cannot add child to already-ended structure element`);
|
||||
}
|
||||
|
||||
if (!this.dictionary.data.K) {
|
||||
this.dictionary.data.K = [];
|
||||
}
|
||||
|
||||
@ -412,6 +412,20 @@ EMC
|
||||
`endobj`
|
||||
]);
|
||||
});
|
||||
|
||||
test('validation', () => {
|
||||
let struct;
|
||||
|
||||
struct = document.struct('Foo').end();
|
||||
expect(() => {
|
||||
struct.add(document.struct('Bar'));
|
||||
}).toThrow();
|
||||
|
||||
struct = document.struct('Foo', []);
|
||||
expect(() => {
|
||||
struct.add(document.struct('Bar'));
|
||||
}).toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('accessible document', () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user