File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# Changelog
22
3+ ## Unreleased
4+
5+ - Added SVG validation: width and height must be specified (in SVG string/element or ` svg ` node)
6+
37## 0.2.22 - 2026-01-07
48
59- Added object type validation for parameters in method ` createPdf ` and ` createPdfKitDocument `
Original file line number Diff line number Diff line change @@ -215,6 +215,15 @@ DocMeasure.prototype.measureSVG = function (node) {
215215
216216 node . font = this . styleStack . getProperty ( 'font' ) ;
217217
218+ // SVG requires a defined width and height
219+ if ( ! isNumber ( node . _width ) && ! isNumber ( node . _height ) ) {
220+ throw new Error ( 'SVG is missing defined width and height.' ) ;
221+ } else if ( ! isNumber ( node . _width ) ) {
222+ throw new Error ( 'SVG is missing defined width.' ) ;
223+ } else if ( ! isNumber ( node . _height ) ) {
224+ throw new Error ( 'SVG is missing defined height.' ) ;
225+ }
226+
218227 // scale SVG based on final dimension
219228 node . svg = this . svgMeasure . writeDimensions ( node . svg , {
220229 width : node . _width ,
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ function isString(variable) {
55}
66
77function isNumber ( variable ) {
8- return typeof variable === 'number' || variable instanceof Number ;
8+ return ( ( typeof variable === 'number' ) || ( variable instanceof Number ) ) && ! Number . isNaN ( variable ) ;
99}
1010
1111function isBoolean ( variable ) {
You can’t perform that action at this time.
0 commit comments