Skip to content

Commit ae736ba

Browse files
committed
make all charAt-calls safe
1 parent 5533a7b commit ae736ba

File tree

6 files changed

+49
-20
lines changed

6 files changed

+49
-20
lines changed

dist/jspdf.debug.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
/** @license
77
* jsPDF - PDF Document creation from JavaScript
8-
* Version 1.5.3 Built on 2018-12-26T04:01:24.767Z
9-
* CommitID 62325b3efa
8+
* Version 1.5.3 Built on 2018-12-26T22:17:53.465Z
9+
* CommitID 5533a7bbbc
1010
*
1111
* Copyright (c) 2010-2016 James Hall <[email protected]>, https://github.com/MrRio/jsPDF
1212
* 2010 Aaron Spike, https://github.com/acspike
@@ -14527,15 +14527,21 @@
1452714527
var instance = data.instance;
1452814528

1452914529
if (typeof instance !== "undefined" && instance.existsFileInVFS(font.postScriptName)) {
14530-
font.metadata = jsPDF.API.TTFFont.open(font.postScriptName, font.fontName, instance.getFileFromVFS(font.postScriptName), font.encoding);
14530+
var file = instance.getFileFromVFS(font.postScriptName);
14531+
14532+
if (typeof file !== "string") {
14533+
throw new Error("Font is not stored as string-data in vFS, import fonts or remove declaration doc.addFont('" + font.postScriptName + "').");
14534+
}
14535+
14536+
font.metadata = jsPDF.API.TTFFont.open(font.postScriptName, font.fontName, file, font.encoding);
1453114537
font.metadata.Unicode = font.metadata.Unicode || {
1453214538
encoding: {},
1453314539
kerning: {},
1453414540
widths: []
1453514541
};
1453614542
font.metadata.glyIdsUsed = [0];
1453714543
} else if (font.isStandardFont === false) {
14538-
throw new Error("Font does not exist in FileInVFS, import fonts or remove declaration doc.addFont('" + font.postScriptName + "').");
14544+
throw new Error("Font does not exist in vFS, import fonts or remove declaration doc.addFont('" + font.postScriptName + "').");
1453914545
}
1454014546
}]); // end of adding event handler
1454114547
})(jsPDF, typeof self !== "undefined" && self || typeof global !== "undefined" && global || typeof window !== "undefined" && window || Function("return this")());
@@ -21609,6 +21615,11 @@
2160921615
/************************************************************************/
2161021616
TTFFont.open = function (filename, name, vfs, encoding) {
2161121617
var contents;
21618+
21619+
if (typeof vfs !== "string") {
21620+
throw new Error('Invalid argument supplied in TTFFont.open');
21621+
}
21622+
2161221623
contents = b64ToByteArray(vfs);
2161321624
return new TTFFont(contents, name, encoding);
2161421625
};

dist/jspdf.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/jspdf.node.debug.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
/** @license
44
* jsPDF - PDF Document creation from JavaScript
5-
* Version 1.5.3 Built on 2018-12-26T04:01:50.595Z
6-
* CommitID 62325b3efa
5+
* Version 1.5.3 Built on 2018-12-26T22:18:16.188Z
6+
* CommitID 5533a7bbbc
77
*
88
* Copyright (c) 2010-2016 James Hall <[email protected]>, https://github.com/MrRio/jsPDF
99
* 2010 Aaron Spike, https://github.com/acspike
@@ -14213,15 +14213,21 @@ var jsPDF = function (global) {
1421314213
var instance = data.instance;
1421414214

1421514215
if (typeof instance !== "undefined" && instance.existsFileInVFS(font.postScriptName)) {
14216-
font.metadata = jsPDF.API.TTFFont.open(font.postScriptName, font.fontName, instance.getFileFromVFS(font.postScriptName), font.encoding);
14216+
var file = instance.getFileFromVFS(font.postScriptName);
14217+
14218+
if (typeof file !== "string") {
14219+
throw new Error("Font is not stored as string-data in vFS, import fonts or remove declaration doc.addFont('" + font.postScriptName + "').");
14220+
}
14221+
14222+
font.metadata = jsPDF.API.TTFFont.open(font.postScriptName, font.fontName, file, font.encoding);
1421714223
font.metadata.Unicode = font.metadata.Unicode || {
1421814224
encoding: {},
1421914225
kerning: {},
1422014226
widths: []
1422114227
};
1422214228
font.metadata.glyIdsUsed = [0];
1422314229
} else if (font.isStandardFont === false) {
14224-
throw new Error("Font does not exist in FileInVFS, import fonts or remove declaration doc.addFont('" + font.postScriptName + "').");
14230+
throw new Error("Font does not exist in vFS, import fonts or remove declaration doc.addFont('" + font.postScriptName + "').");
1422514231
}
1422614232
}]); // end of adding event handler
1422714233
})(jsPDF, typeof self !== "undefined" && self || typeof global !== "undefined" && global || typeof window !== "undefined" && window || Function("return this")());
@@ -18431,6 +18437,11 @@ var jsPDF = function (global) {
1843118437
/************************************************************************/
1843218438
TTFFont.open = function (filename, name, vfs, encoding) {
1843318439
var contents;
18440+
18441+
if (typeof vfs !== "string") {
18442+
throw new Error('Invalid argument supplied in TTFFont.open');
18443+
}
18444+
1843418445
contents = b64ToByteArray(vfs);
1843518446
return new TTFFont(contents, name, encoding);
1843618447
};

dist/jspdf.node.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/libs/ttffont.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
/* by Byte array and stored. */
2424
/*****************************************************************/
2525
var b64ToByteArray = function(b64) {
26-
var i, j, l, tmp, placeHolders, arr
26+
var i, j, l, tmp, placeHolders, arr;
2727
if (b64.length % 4 > 0) {
28-
throw new Error('Invalid string. Length must be a multiple of 4')
28+
throw new Error('Invalid string. Length must be a multiple of 4');
2929
}
3030
// the number of equal signs (place holders)
3131
// if there are two placeholders, than the two characters before it
@@ -83,6 +83,9 @@
8383
/************************************************************************/
8484
TTFFont.open = function (filename, name, vfs, encoding) {
8585
var contents;
86+
if (typeof vfs !== "string") {
87+
throw new Error('Invalid argument supplied in TTFFont.open');
88+
}
8689
contents = b64ToByteArray(vfs);
8790
return new TTFFont(contents, name, encoding);
8891
};

src/modules/ttfsupport.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@
1616
var font = data.font;
1717
var instance = data.instance;
1818
if (typeof instance !== "undefined" && instance.existsFileInVFS(font.postScriptName)) {
19-
font.metadata = jsPDF.API.TTFFont.open(font.postScriptName, font.fontName, instance.getFileFromVFS(font.postScriptName), font.encoding);
19+
var file = instance.getFileFromVFS(font.postScriptName);
20+
if (typeof file !== "string") {
21+
throw new Error("Font is not stored as string-data in vFS, import fonts or remove declaration doc.addFont('" + font.postScriptName + "').");
22+
}
23+
font.metadata = jsPDF.API.TTFFont.open(font.postScriptName, font.fontName, file, font.encoding);
2024
font.metadata.Unicode = font.metadata.Unicode || {encoding: {}, kerning: {}, widths: []};
2125
font.metadata.glyIdsUsed = [0];
2226
} else if (font.isStandardFont === false) {
23-
throw new Error("Font does not exist in FileInVFS, import fonts or remove declaration doc.addFont('" + font.postScriptName + "').");
27+
throw new Error("Font does not exist in vFS, import fonts or remove declaration doc.addFont('" + font.postScriptName + "').");
2428
}
2529
}
2630
]) // end of adding event handler

0 commit comments

Comments
 (0)