mirror of
https://github.com/foliojs/pdfkit.git
synced 2026-02-01 16:56:57 +00:00
Guard against adding a structure element to more than one parent.
This commit is contained in:
parent
2ed3782473
commit
4c4a49ebff
@ -10,7 +10,6 @@ class PDFStructureElement {
|
||||
this.document = document;
|
||||
|
||||
this._ended = false;
|
||||
this._flushed = false;
|
||||
this.dictionary = document.ref({
|
||||
// Type: "StructElem",
|
||||
S: type
|
||||
@ -92,6 +91,10 @@ class PDFStructureElement {
|
||||
}
|
||||
|
||||
setParent(parentRef) {
|
||||
if (this.dictionary.data.P) {
|
||||
throw new Error(`Structure element added to more than one parent`);
|
||||
}
|
||||
|
||||
this.dictionary.data.P = parentRef;
|
||||
|
||||
if (this._ended) {
|
||||
|
||||
@ -426,6 +426,12 @@ EMC
|
||||
struct.add(document.struct('Bar'));
|
||||
}).toThrow();
|
||||
|
||||
struct = document.struct('Foo');
|
||||
let parent = document.struct('Bar').add(struct);
|
||||
expect(() => {
|
||||
parent.add(struct);
|
||||
}).toThrow();
|
||||
|
||||
expect(() => {
|
||||
document.struct('Foo', [1]);
|
||||
}).toThrow();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user