From 82f7c09b9e217f5ab22ca00e74038ed327d8eea8 Mon Sep 17 00:00:00 2001 From: aakash-gitdev Date: Tue, 19 Apr 2022 21:43:11 +0530 Subject: [PATCH 1/2] Added MaxNickNameLength and MaxBioLength constants added above mentioned constants to remove magic numbers in a simple manner --- apps/meteor/app/lib/server/functions/saveUser.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/meteor/app/lib/server/functions/saveUser.js b/apps/meteor/app/lib/server/functions/saveUser.js index 736221d2e3af..279450008786 100644 --- a/apps/meteor/app/lib/server/functions/saveUser.js +++ b/apps/meteor/app/lib/server/functions/saveUser.js @@ -227,8 +227,9 @@ export function validateUserEditing(userId, userData) { } const handleBio = (updateUser, bio) => { + const MaxBioLength = 260; if (bio && bio.trim()) { - if (typeof bio !== 'string' || bio.length > 260) { + if (typeof bio !== 'string' || bio.length > MaxBioLength) { throw new Meteor.Error('error-invalid-field', 'bio', { method: 'saveUserProfile', }); @@ -242,8 +243,9 @@ const handleBio = (updateUser, bio) => { }; const handleNickname = (updateUser, nickname) => { + const MaxNickNameLength = 120; if (nickname && nickname.trim()) { - if (typeof nickname !== 'string' || nickname.length > 120) { + if (typeof nickname !== 'string' || nickname.length > MaxNickNameLength) { throw new Meteor.Error('error-invalid-field', 'nickname', { method: 'saveUserProfile', }); From 88ae2bde5f8f760e700f624ad3076671f382b0bb Mon Sep 17 00:00:00 2001 From: gabriellsh <40830821+gabriellsh@users.noreply.github.com> Date: Tue, 19 Apr 2022 14:52:02 -0300 Subject: [PATCH 2/2] code style fixes --- apps/meteor/app/lib/server/functions/saveUser.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/apps/meteor/app/lib/server/functions/saveUser.js b/apps/meteor/app/lib/server/functions/saveUser.js index 279450008786..787686ff72c3 100644 --- a/apps/meteor/app/lib/server/functions/saveUser.js +++ b/apps/meteor/app/lib/server/functions/saveUser.js @@ -15,6 +15,9 @@ import { checkEmailAvailability, checkUsernameAvailability, setUserAvatar, setEm import { Users } from '../../../models/server'; import { callbacks } from '../../../../lib/callbacks'; +const MAX_BIO_LENGTH = 260; +const MAX_NICKNAME_LENGTH = 120; + let html = ''; let passwordChangedHtml = ''; Meteor.startup(() => { @@ -227,9 +230,8 @@ export function validateUserEditing(userId, userData) { } const handleBio = (updateUser, bio) => { - const MaxBioLength = 260; if (bio && bio.trim()) { - if (typeof bio !== 'string' || bio.length > MaxBioLength) { + if (typeof bio !== 'string' || bio.length > MAX_BIO_LENGTH) { throw new Meteor.Error('error-invalid-field', 'bio', { method: 'saveUserProfile', }); @@ -243,9 +245,8 @@ const handleBio = (updateUser, bio) => { }; const handleNickname = (updateUser, nickname) => { - const MaxNickNameLength = 120; if (nickname && nickname.trim()) { - if (typeof nickname !== 'string' || nickname.length > MaxNickNameLength) { + if (typeof nickname !== 'string' || nickname.length > MAX_NICKNAME_LENGTH) { throw new Meteor.Error('error-invalid-field', 'nickname', { method: 'saveUserProfile', });