From 05a33f15331bac551010585c0890a40e6421771f Mon Sep 17 00:00:00 2001 From: muxator Date: Wed, 29 Aug 2018 02:08:05 +0200 Subject: [PATCH] db/API.js, SessionManager: lot of copied & pasted code in integer parsing Replaced with an early return, no functional changes. --- src/node/db/API.js | 56 +++++++++++++---------------------- src/node/db/SessionManager.js | 8 ++--- 2 files changed, 24 insertions(+), 40 deletions(-) diff --git a/src/node/db/API.js b/src/node/db/API.js index 7c6b95117..c420b9994 100644 --- a/src/node/db/API.js +++ b/src/node/db/API.js @@ -137,15 +137,13 @@ exports.getRevisionChangeset = function(padID, rev, callback) if (rev !== undefined && typeof rev !== "number") { // try to parse the number - if (!isNaN(parseInt(rev))) - { - rev = parseInt(rev); - } - else + if (isNaN(parseInt(rev))) { callback(new customError("rev is not a number", "apierror")); return; } + + rev = parseInt(rev); } // ensure this is not a negative number @@ -219,15 +217,13 @@ exports.getText = function(padID, rev, callback) if(rev !== undefined && typeof rev != "number") { //try to parse the number - if(!isNaN(parseInt(rev))) - { - rev = parseInt(rev); - } - else + if(isNaN(parseInt(rev))) { callback(new customError("rev is not a number", "apierror")); return; } + + rev = parseInt(rev); } //ensure this is not a negativ number @@ -359,15 +355,13 @@ exports.getHTML = function(padID, rev, callback) if (rev !== undefined && typeof rev != "number") { - if (!isNaN(parseInt(rev))) - { - rev = parseInt(rev); - } - else + if (isNaN(parseInt(rev))) { callback(new customError("rev is not a number","apierror")); return; } + + rev = parseInt(rev); } if(rev !== undefined && rev < 0) @@ -641,15 +635,13 @@ exports.saveRevision = function(padID, rev, callback) if(rev !== undefined && typeof rev != "number") { //try to parse the number - if(!isNaN(parseInt(rev))) - { - rev = parseInt(rev); - } - else + if(isNaN(parseInt(rev))) { callback(new customError("rev is not a number", "apierror")); return; } + + rev = parseInt(rev); } //ensure this is not a negativ number @@ -782,15 +774,13 @@ exports.restoreRevision = function (padID, rev, callback) if (rev !== undefined && typeof rev != "number") { //try to parse the number - if (!isNaN(parseInt(rev))) - { - rev = parseInt(rev); - } - else + if (isNaN(parseInt(rev))) { callback(new customError("rev is not a number", "apierror")); return; } + + rev = parseInt(rev); } //ensure this is not a negativ number @@ -1177,30 +1167,26 @@ exports.createDiffHTML = function(padID, startRev, endRev, callback){ if(startRev !== undefined && typeof startRev != "number") { //try to parse the number - if(!isNaN(parseInt(startRev))) - { - startRev = parseInt(startRev, 10); - } - else + if(isNaN(parseInt(startRev))) { callback({stop: "startRev is not a number"}); return; } + + startRev = parseInt(startRev, 10); } //check if rev is a number if(endRev !== undefined && typeof endRev != "number") { //try to parse the number - if(!isNaN(parseInt(endRev))) - { - endRev = parseInt(endRev, 10); - } - else + if(isNaN(parseInt(endRev))) { callback({stop: "endRev is not a number"}); return; } + + endRev = parseInt(endRev, 10); } //get the pad diff --git a/src/node/db/SessionManager.js b/src/node/db/SessionManager.js index 518c70c7a..954203758 100644 --- a/src/node/db/SessionManager.js +++ b/src/node/db/SessionManager.js @@ -90,15 +90,13 @@ exports.createSession = function(groupID, authorID, validUntil, callback) if(typeof validUntil != "number") { //try to parse the number - if(!isNaN(parseInt(validUntil))) - { - validUntil = parseInt(validUntil); - } - else + if(isNaN(parseInt(validUntil))) { callback(new customError("validUntil is not a number","apierror")); return; } + + validUntil = parseInt(validUntil); } //ensure this is not a negativ number