Node.js based forum software built for the modern web
fix: getUserField so that it always returns null
Barış Soner Uşaklıe85662a536bf
diff --git a/src/user/data.js b/src/user/data.jsindex ec643f729b..c9d8cb5ae6 100644--- a/src/user/data.js+++ b/src/user/data.js@@ -161,7 +161,7 @@ module.exports = function (User) {User.getUserField = async function (uid, field) {const user = await User.getUserFields(uid, [field]);- return user ? user[field] : null;+ return user && user.hasOwnProperty(field) ? user[field] : null;};User.getUserFields = async function (uid, fields) {diff --git a/test/user.js b/test/user.jsindex 84d8711260..579386b166 100644--- a/test/user.js+++ b/test/user.js@@ -680,6 +680,12 @@ describe('User', () => {done();});});++ it('should return null if field or user doesn not exist', async () => {+ assert.strictEqual(await User.getUserField('1', 'doesnotexist'), null);+ assert.strictEqual(await User.getUserField('doesnotexistkey', 'doesnotexist'), null);+ assert.strictEqual(await User.getUserField('0', 'doesnotexist'), null);+ });});describe('profile methods', () => {