Skip to content

Build your personal knowledge base with Trilium Notes

fix(isEmptyOrWhitespace): avoid exception throwing when passed value is undefined

Panagiotis Papadopoulos03c1128a726b
diff --git a/src/routes/api/branches.ts b/src/routes/api/branches.ts
index 746ebb92ad..b9c5f751d2 100644
--- a/src/routes/api/branches.ts
+++ b/src/routes/api/branches.ts
@@ -216,6 +216,7 @@ function deleteBranch(req: Request) {
function setPrefix(req: Request) {
const branchId = req.params.branchId;
+ //TriliumNextTODO: req.body arrives as string, so req.body.prefix will be undefined – did the code below ever even work?
const prefix = utils.isEmptyOrWhitespace(req.body.prefix) ? null : req.body.prefix;
const branch = becca.getBranchOrThrow(branchId);
diff --git a/src/services/utils.ts b/src/services/utils.ts
index b00c1e4889..f101f6064a 100644
--- a/src/services/utils.ts
+++ b/src/services/utils.ts
@@ -71,8 +71,9 @@ export function hash(text: string) {
return crypto.createHash("sha1").update(text).digest("base64");
}
-export function isEmptyOrWhitespace(str: string) {
- return str === null || str.match(/^ *$/) !== null;
+export function isEmptyOrWhitespace(str: string | null | undefined) {
+ if (!str) return true;
+ return str.match(/^ *$/) !== null;
}
export function sanitizeSqlIdentifier(str: string) {