Skip to content

Node.js based forum software built for the modern web

fix: #8418

Barış Soner Uşaklı38d3982bf138
diff --git a/src/user/profile.js b/src/user/profile.js
index 05a6b8b3de..c7c4af7bbd 100644
--- a/src/user/profile.js
+++ b/src/user/profile.js
@@ -86,7 +86,9 @@ module.exports = function (User) {
}
data.username = data.username.trim();
const userData = await User.getUserFields(uid, ['username', 'userslug']);
- var userslug = utils.slugify(data.username);
+ if (userData.username === data.username) {
+ return;
+ }
if (data.username.length < meta.config.minimumUsernameLength) {
throw new Error('[[error:username-too-short]]');
@@ -96,6 +98,7 @@ module.exports = function (User) {
throw new Error('[[error:username-too-long]]');
}
+ const userslug = utils.slugify(data.username);
if (!utils.isUserNameValid(data.username) || !userslug) {
throw new Error('[[error:invalid-username]]');
}
diff --git a/test/user.js b/test/user.js
index 70bc1977fc..306244f0d5 100644
--- a/test/user.js
+++ b/test/user.js
@@ -900,6 +900,22 @@ describe('User', function () {
});
});
+ it('should not let setting an empty username', async function () {
+ await socketUser.changeUsernameEmail({ uid: uid }, { uid: uid, username: '', password: '123456' });
+ const username = await db.getObjectField('user:' + uid, 'username');
+ assert.strictEqual(username, 'updatedAgain');
+ });
+
+ it('should let updating profile if current username is above max length and it is not being changed', async function () {
+ const maxLength = meta.config.maximumUsernameLength + 1;
+ const longName = new Array(maxLength).fill('a').join('');
+ const uid = await User.create({ username: longName });
+ await socketUser.changeUsernameEmail({ uid: uid }, { uid: uid, username: longName, email: '[email protected]' });
+ const userData = await db.getObject('user:' + uid);
+ assert.strictEqual(userData.username, longName);
+ assert.strictEqual(userData.email, '[email protected]');
+ });
+
it('should not update a user\'s username if it did not change', function (done) {
socketUser.changeUsernameEmail({ uid: uid }, { uid: uid, username: 'updatedAgain', password: '123456' }, function (err) {
assert.ifError(err);