Skip to content

Commit

Permalink
Merge pull request #2872 from skchawala/allow_number_in_table_cell
Browse files Browse the repository at this point in the history
Fix-splitTextToSize method crashes if cell value is not a string #2849
  • Loading branch information
HackbrettXXX authored Aug 25, 2020
2 parents ab21994 + 02c7faa commit 078d0fb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/modules/cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,13 @@ import { jsPDF } from "../jspdf.js";
var tempWidth = 0;

if (!Array.isArray(text) && typeof text !== "string") {
throw new Error(
"getTextDimensions expects text-parameter to be of type String or an Array of Strings."
);
if (typeof text === "number") {
text = String(text);
} else {
throw new Error(
"getTextDimensions expects text-parameter to be of type String or type Number or an Array of Strings."
);
}
}

const maxWidth = options.maxWidth;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/split_text_to_size.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ import { jsPDF } from "../jspdf.js";
if (Array.isArray(text)) {
paragraphs = text;
} else {
paragraphs = text.split(/\r?\n/);
paragraphs = String(text).split(/\r?\n/);
}

// now we convert size (max length of line) into "font size units"
Expand Down
2 changes: 1 addition & 1 deletion test/specs/cell.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe("Module: Cell", () => {
doc.getTextDimensions();
}).toThrow(
new Error(
"getTextDimensions expects text-parameter to be of type String or an Array of Strings."
"getTextDimensions expects text-parameter to be of type String or type Number or an Array of Strings."
)
);
});
Expand Down

0 comments on commit 078d0fb

Please sign in to comment.