diff --git a/src/routes/api/branches.ts b/src/routes/api/branches.ts index 746ebb92a..b9c5f751d 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 b00c1e488..f101f6064 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) {