Skip to content

Commit c82622d

Browse files
authored
Fix: always pop render target stack in endFormObject (#3135)
1 parent cbc85b4 commit c82622d

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/jspdf.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5689,7 +5689,10 @@ function jsPDF(options) {
56895689

56905690
var endFormObject = function(key) {
56915691
// only add it if it is not already present (the keys provided by the user must be unique!)
5692-
if (renderTargetMap[key]) return;
5692+
if (renderTargetMap[key]) {
5693+
renderTargetStack.pop().restore();
5694+
return;
5695+
}
56935696

56945697
// save the created xObject
56955698
var newXObject = new RenderTarget();

test/specs/jspdf.unit.spec.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3056,8 +3056,7 @@ This is a test too.`,
30563056
writeArray = [];
30573057
doc.__private__.setCustomOutputDestination(writeArray);
30583058
doc.__private__.putStream({
3059-
data:
3060-
"x\u009C+.)JMÌuI,I\u0004\u0000\u0016Ò\u0004\u0007",
3059+
data: "x\u009C+.)JMÌuI,I\u0004\u0000\u0016Ò\u0004\u0007",
30613060
alreadyAppliedFilters: ["/FlateDecode"]
30623061
});
30633062
expect(bufferFromString(writeArray.join("\n"))).toEqual(expected);
@@ -3100,6 +3099,7 @@ This is a test too.`,
31003099
objId: 3,
31013100
contentsObjId: 4
31023101
});
3102+
31033103
expect(writeArray).toEqual([
31043104
"3 0 obj",
31053105
"<</Type /Page",
@@ -3607,6 +3607,25 @@ This is a test too.`,
36073607
"%%EOF"
36083608
]);
36093609
});
3610+
3611+
it("jsPdf public function beginFormObject, endFormObject", () => {
3612+
var doc = jsPDF();
3613+
var startContext = doc.internal.getCurrentPageInfo().pageContext;
3614+
doc.beginFormObject(0, 0, 100, 100, new doc.internal.Matrix(1, 0, 0, 1, 0, 0));
3615+
expect(doc.internal.getCurrentPageInfo().pageContext).not.toEqual(
3616+
startContext
3617+
);
3618+
doc.endFormObject("testFormObject");
3619+
expect(doc.internal.getCurrentPageInfo().pageContext).toEqual(startContext);
3620+
3621+
// Adding a form object with the same id twice should keep stack intact
3622+
doc.beginFormObject(0, 0, 100, 100, new doc.internal.Matrix(1, 0, 0, 1, 0, 0));
3623+
expect(doc.internal.getCurrentPageInfo().pageContext).not.toEqual(
3624+
startContext
3625+
);
3626+
doc.endFormObject("testFormObject");
3627+
expect(doc.internal.getCurrentPageInfo().pageContext).toEqual(startContext);
3628+
});
36103629
});
36113630

36123631
function bufferFromString(string) {

0 commit comments

Comments
 (0)