diff --git a/src/database/redis/sorted.js b/src/database/redis/sorted.js index 9bb004550a..282928da97 100644 --- a/src/database/redis/sorted.js +++ b/src/database/redis/sorted.js @@ -129,7 +129,13 @@ module.exports = function (redisClient, module) { } redisClient.zscore(key, value, function (err, score) { - callback(err, !err ? parseFloat(score) : null); + if (err) { + return callback(err); + } + if (score === null) { + return callback(null, score); + } + callback(null, parseFloat(score)); }); }; diff --git a/src/user/bans.js b/src/user/bans.js index ad51c7c07c..e2cf2193b3 100644 --- a/src/user/bans.js +++ b/src/user/bans.js @@ -61,7 +61,7 @@ module.exports = function (User) { async.waterfall([ async.apply(User.getUserFields, uid, ['banned', 'banned:expire']), function (userData, next) { - var banned = parseInt(userData.banned, 10) === 1; + var banned = userData && parseInt(userData.banned, 10) === 1; if (!banned) { return next(null, banned); } diff --git a/test/database/hash.js b/test/database/hash.js index 7f9dc305d0..cffa761229 100644 --- a/test/database/hash.js +++ b/test/database/hash.js @@ -190,6 +190,15 @@ describe('Hash methods', function () { done(); }); }); + + it('should return undefined for all fields if object does not exist', function (done) { + db.getObjectsFields(['doesnotexist1', 'doesnotexist2'], ['name', 'age'], function (err, data) { + assert.ifError(err); + assert.equal(data.name, null); + assert.equal(data.age, null); + done(); + }); + }); }); describe('getObjectKeys()', function () { diff --git a/test/database/sorted.js b/test/database/sorted.js index b90e9cf71f..9e0178d4ed 100644 --- a/test/database/sorted.js +++ b/test/database/sorted.js @@ -303,6 +303,7 @@ describe('Sorted Set methods', function () { assert.equal(err, null); assert.equal(arguments.length, 2); assert.equal(!!score, false); + assert.strictEqual(score, null); done(); }); }); @@ -312,6 +313,7 @@ describe('Sorted Set methods', function () { assert.equal(err, null); assert.equal(arguments.length, 2); assert.equal(!!score, false); + assert.strictEqual(score, null); done(); }); });