mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-09-18 17:31:53 +08:00
fix(isEmptyOrWhitespace): avoid exception throwing when passed value is undefined
the req.body value from "routes/api/branches" actually seems to never get parsed into a JS object, but arrives as text string, so req.body.prefix could be undefined, which of course would cause an error to be thrown, when trying to call "match" on undefined.
This commit is contained in:
parent
8546fe2333
commit
03c1128a72
@ -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);
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user