Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix-splitTextToSize method crashes if cell value is not a string #2849 #2872

Merged
merged 1 commit into from
Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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